Okay, hopefully this is the last question today!
I've found the below formula in one of the posts here, but my brain has
completely failed on me and I'm not sure how to adapt it to my requirements.
I have a value which is entered by the user after a prompt, that populates
in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
is 30/11/09.
I have another worksheet, 'Data', which has a column populated with dates
(say column B). I'd like a macro that looks in column B on the data sheet,
and clears out any dates which are greater than the value in cell G4. I just
want to empty those cells, not delete columns or anything else.
Sub sth()
Dim cell As Range
For Each cell In Selection
If cell.Value < 1000 Then
cell.ClearContents
End If
Next cell
End Sub
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 1:02:01 PM |
|
Hi,
Try this
Sub sth()
Dim LastRow as long
lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
For Each c In MyRange
If c.Value > Sheets("lookup").Range("G4") Then
c.ClearContents
End If
Next
Mike
"bawpie" wrote:
> Okay, hopefully this is the last question today!
>
> I've found the below formula in one of the posts here, but my brain has
> completely failed on me and I'm not sure how to adapt it to my requirements.
>
> I have a value which is entered by the user after a prompt, that populates
> in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> is 30/11/09.
>
> I have another worksheet, 'Data', which has a column populated with dates
> (say column B). I'd like a macro that looks in column B on the data sheet,
> and clears out any dates which are greater than the value in cell G4. I just
> want to empty those cells, not delete columns or anything else.
>
> Sub sth()
> Dim cell As Range
>
> For Each cell In Selection
> If cell.Value < 1000 Then
> cell.ClearContents
> End If
> Next cell
>
>
> End Sub
>
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 1:11:01 PM
|
|
Hi,
If you want to do it with 'selection' then select the range and use this
Sub sth()
For Each c In Selection
If c.Value > Sheets("lookup").Range("G4") Then
c.ClearContents
End If
Next
End Sub
Mike
"Mike H" wrote:
> Hi,
>
> Try this
>
> Sub sth()
> Dim LastRow as long
> lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
> Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
> For Each c In MyRange
> If c.Value > Sheets("lookup").Range("G4") Then
> c.ClearContents
> End If
> Next
>
> Mike
>
> "bawpie" wrote:
>
> > Okay, hopefully this is the last question today!
> >
> > I've found the below formula in one of the posts here, but my brain has
> > completely failed on me and I'm not sure how to adapt it to my requirements.
> >
> > I have a value which is entered by the user after a prompt, that populates
> > in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> > is 30/11/09.
> >
> > I have another worksheet, 'Data', which has a column populated with dates
> > (say column B). I'd like a macro that looks in column B on the data sheet,
> > and clears out any dates which are greater than the value in cell G4. I just
> > want to empty those cells, not delete columns or anything else.
> >
> > Sub sth()
> > Dim cell As Range
> >
> > For Each cell In Selection
> > If cell.Value < 1000 Then
> > cell.ClearContents
> > End If
> > Next cell
> >
> >
> > End Sub
> >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 1:20:01 PM
|
|
Okay,
I've tried the below, and it is working except:
For some reason it deletes the header from B1 (this is easily solved though
by setting the range as B2:B & Last Row).
Also, I'm using the following piece of code for the input (G4)
Sheets("Lookup").Range("G4").Value = InputBox("Please enter the end of
Period (dd/mm/yy)", "Report Year")
Now I think when it's populating the box, it's doing so as a string rather
than a number - so the macro doesn't work (although funnily enough that
reference does work as a date in a formula I'm also using). If I just type
in a date (say into G5) and then reference that, the macro understands it
perfectly.
So I guess I need to figure out how to tweak my input so it's returned as a
true date rather than a string? I tried just recording macro which would
simply change G4 to text to columns prior to running your code (messy yes,
but I thought it would work) but it doesn't seem to...
"Mike H" wrote:
> Hi,
>
> Try this
>
> Sub sth()
> Dim LastRow as long
> lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
> Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
> For Each c In MyRange
> If c.Value > Sheets("lookup").Range("G4") Then
> c.ClearContents
> End If
> Next
>
> Mike
>
> "bawpie" wrote:
>
> > Okay, hopefully this is the last question today!
> >
> > I've found the below formula in one of the posts here, but my brain has
> > completely failed on me and I'm not sure how to adapt it to my requirements.
> >
> > I have a value which is entered by the user after a prompt, that populates
> > in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> > is 30/11/09.
> >
> > I have another worksheet, 'Data', which has a column populated with dates
> > (say column B). I'd like a macro that looks in column B on the data sheet,
> > and clears out any dates which are greater than the value in cell G4. I just
> > want to empty those cells, not delete columns or anything else.
> >
> > Sub sth()
> > Dim cell As Range
> >
> > For Each cell In Selection
> > If cell.Value < 1000 Then
> > cell.ClearContents
> > End If
> > Next cell
> >
> >
> > End Sub
> >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 1:39:02 PM
|
|
Like this
Sheets("Lookup").Range("G4").Value = _
Format(InputBox("Please enter the end of Period (dd/mm/yy)", "Report Year"),
"dd/mm/yyyy")
Mike
"bawpie" wrote:
> Okay,
>
> I've tried the below, and it is working except:
>
> For some reason it deletes the header from B1 (this is easily solved though
> by setting the range as B2:B & Last Row).
>
> Also, I'm using the following piece of code for the input (G4)
>
> Sheets("Lookup").Range("G4").Value = InputBox("Please enter the end of
> Period (dd/mm/yy)", "Report Year")
>
> Now I think when it's populating the box, it's doing so as a string rather
> than a number - so the macro doesn't work (although funnily enough that
> reference does work as a date in a formula I'm also using). If I just type
> in a date (say into G5) and then reference that, the macro understands it
> perfectly.
>
> So I guess I need to figure out how to tweak my input so it's returned as a
> true date rather than a string? I tried just recording macro which would
> simply change G4 to text to columns prior to running your code (messy yes,
> but I thought it would work) but it doesn't seem to...
>
> "Mike H" wrote:
>
> > Hi,
> >
> > Try this
> >
> > Sub sth()
> > Dim LastRow as long
> > lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
> > For Each c In MyRange
> > If c.Value > Sheets("lookup").Range("G4") Then
> > c.ClearContents
> > End If
> > Next
> >
> > Mike
> >
> > "bawpie" wrote:
> >
> > > Okay, hopefully this is the last question today!
> > >
> > > I've found the below formula in one of the posts here, but my brain has
> > > completely failed on me and I'm not sure how to adapt it to my requirements.
> > >
> > > I have a value which is entered by the user after a prompt, that populates
> > > in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> > > is 30/11/09.
> > >
> > > I have another worksheet, 'Data', which has a column populated with dates
> > > (say column B). I'd like a macro that looks in column B on the data sheet,
> > > and clears out any dates which are greater than the value in cell G4. I just
> > > want to empty those cells, not delete columns or anything else.
> > >
> > > Sub sth()
> > > Dim cell As Range
> > >
> > > For Each cell In Selection
> > > If cell.Value < 1000 Then
> > > cell.ClearContents
> > > End If
> > > Next cell
> > >
> > >
> > > End Sub
> > >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 2:59:01 PM
|
|
Mike,
Thanks. I've tried that, and when G4 is populated it is formatted as
30/11/2009 but it's still a string rather than a number, so the previous
macro doesn't work.
If I enter a date in the cell below, it enters as a date and goes to the
left side of the cell - but the data taken from the input box sits on the
right (which is behaviour for text I think?) Checking the format type on
both cells reveals them to be date formatted.
I know I can simply have the user put the date into a box, but I liked the
idea of having the input box as it would force them to update prior to
running the macro.
Thanks for your continued assistance!
"Mike H" wrote:
> Like this
>
> Sheets("Lookup").Range("G4").Value = _
> Format(InputBox("Please enter the end of Period (dd/mm/yy)", "Report Year"),
> "dd/mm/yyyy")
>
>
> Mike
>
> "bawpie" wrote:
>
> > Okay,
> >
> > I've tried the below, and it is working except:
> >
> > For some reason it deletes the header from B1 (this is easily solved though
> > by setting the range as B2:B & Last Row).
> >
> > Also, I'm using the following piece of code for the input (G4)
> >
> > Sheets("Lookup").Range("G4").Value = InputBox("Please enter the end of
> > Period (dd/mm/yy)", "Report Year")
> >
> > Now I think when it's populating the box, it's doing so as a string rather
> > than a number - so the macro doesn't work (although funnily enough that
> > reference does work as a date in a formula I'm also using). If I just type
> > in a date (say into G5) and then reference that, the macro understands it
> > perfectly.
> >
> > So I guess I need to figure out how to tweak my input so it's returned as a
> > true date rather than a string? I tried just recording macro which would
> > simply change G4 to text to columns prior to running your code (messy yes,
> > but I thought it would work) but it doesn't seem to...
> >
> > "Mike H" wrote:
> >
> > > Hi,
> > >
> > > Try this
> > >
> > > Sub sth()
> > > Dim LastRow as long
> > > lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > > Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
> > > For Each c In MyRange
> > > If c.Value > Sheets("lookup").Range("G4") Then
> > > c.ClearContents
> > > End If
> > > Next
> > >
> > > Mike
> > >
> > > "bawpie" wrote:
> > >
> > > > Okay, hopefully this is the last question today!
> > > >
> > > > I've found the below formula in one of the posts here, but my brain has
> > > > completely failed on me and I'm not sure how to adapt it to my requirements.
> > > >
> > > > I have a value which is entered by the user after a prompt, that populates
> > > > in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> > > > is 30/11/09.
> > > >
> > > > I have another worksheet, 'Data', which has a column populated with dates
> > > > (say column B). I'd like a macro that looks in column B on the data sheet,
> > > > and clears out any dates which are greater than the value in cell G4. I just
> > > > want to empty those cells, not delete columns or anything else.
> > > >
> > > > Sub sth()
> > > > Dim cell As Range
> > > >
> > > > For Each cell In Selection
> > > > If cell.Value < 1000 Then
> > > > cell.ClearContents
> > > > End If
> > > > Next cell
> > > >
> > > >
> > > > End Sub
> > > >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 3:25:01 PM
|
|
Ah, got it. Changed my input to:
Dim Period As Date
Period = InputBox("Please enter the end of Period (dd/mm/yyyy)", "Report
Year")
Sheets("Lookup").Select
Range("G4").Value = Period
And now it works flawlessly with your macro. Thanks very much!
"bawpie" wrote:
> Mike,
>
> Thanks. I've tried that, and when G4 is populated it is formatted as
> 30/11/2009 but it's still a string rather than a number, so the previous
> macro doesn't work.
>
> If I enter a date in the cell below, it enters as a date and goes to the
> left side of the cell - but the data taken from the input box sits on the
> right (which is behaviour for text I think?) Checking the format type on
> both cells reveals them to be date formatted.
>
> I know I can simply have the user put the date into a box, but I liked the
> idea of having the input box as it would force them to update prior to
> running the macro.
>
> Thanks for your continued assistance!
>
> "Mike H" wrote:
>
> > Like this
> >
> > Sheets("Lookup").Range("G4").Value = _
> > Format(InputBox("Please enter the end of Period (dd/mm/yy)", "Report Year"),
> > "dd/mm/yyyy")
> >
> >
> > Mike
> >
> > "bawpie" wrote:
> >
> > > Okay,
> > >
> > > I've tried the below, and it is working except:
> > >
> > > For some reason it deletes the header from B1 (this is easily solved though
> > > by setting the range as B2:B & Last Row).
> > >
> > > Also, I'm using the following piece of code for the input (G4)
> > >
> > > Sheets("Lookup").Range("G4").Value = InputBox("Please enter the end of
> > > Period (dd/mm/yy)", "Report Year")
> > >
> > > Now I think when it's populating the box, it's doing so as a string rather
> > > than a number - so the macro doesn't work (although funnily enough that
> > > reference does work as a date in a formula I'm also using). If I just type
> > > in a date (say into G5) and then reference that, the macro understands it
> > > perfectly.
> > >
> > > So I guess I need to figure out how to tweak my input so it's returned as a
> > > true date rather than a string? I tried just recording macro which would
> > > simply change G4 to text to columns prior to running your code (messy yes,
> > > but I thought it would work) but it doesn't seem to...
> > >
> > > "Mike H" wrote:
> > >
> > > > Hi,
> > > >
> > > > Try this
> > > >
> > > > Sub sth()
> > > > Dim LastRow as long
> > > > lastrow = Sheets("Data").Cells(Cells.Rows.Count, "B").End(xlUp).Row
> > > > Set MyRange = Sheets("Data").Range("B1:B" & lastrow)
> > > > For Each c In MyRange
> > > > If c.Value > Sheets("lookup").Range("G4") Then
> > > > c.ClearContents
> > > > End If
> > > > Next
> > > >
> > > > Mike
> > > >
> > > > "bawpie" wrote:
> > > >
> > > > > Okay, hopefully this is the last question today!
> > > > >
> > > > > I've found the below formula in one of the posts here, but my brain has
> > > > > completely failed on me and I'm not sure how to adapt it to my requirements.
> > > > >
> > > > > I have a value which is entered by the user after a prompt, that populates
> > > > > in cell G4 in a sheet called 'Lookup'. For arguments sake, the current value
> > > > > is 30/11/09.
> > > > >
> > > > > I have another worksheet, 'Data', which has a column populated with dates
> > > > > (say column B). I'd like a macro that looks in column B on the data sheet,
> > > > > and clears out any dates which are greater than the value in cell G4. I just
> > > > > want to empty those cells, not delete columns or anything else.
> > > > >
> > > > > Sub sth()
> > > > > Dim cell As Range
> > > > >
> > > > > For Each cell In Selection
> > > > > If cell.Value < 1000 Then
> > > > > cell.ClearContents
> > > > > End If
> > > > > Next cell
> > > > >
> > > > >
> > > > > End Sub
> > > > >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/22/2009 3:38:01 PM
|
|
|
6 Replies
310 Views
(page loaded in 0.112 seconds)
Similiar Articles: If cell value is greater than another cell value, clear contents ...Okay, hopefully this is the last question today! I've found the below formula in one of the posts here, but my brain has completely failed on me ... Delete contents of cells in a range based on value of a cell ...If cell value is greater than another cell value, clear contents ... Delete contents of cells in a range based on value of a cell ..... contents of cells in a range based ... Need to clear cell values, when a different cell is changed ...Need to clear cell values, when a different cell is changed ... If cell value is greater than another cell value, clear contents ... > > > So I guess I need to figure out ... How to check if the values in a range of cells are greater than 0 ...How to check if the values in a range of cells are greater than 0 ... If cell value is greater than another cell value, clear contents ... How to check if the values ... Macro to clear contents of certain cells - microsoft.public.excel ...Macro to clear contents of certain cells - microsoft.public.excel ... Delete contents of cells in a range based on value of a cell ... Macro to clear contents of ... If statement in macro to find blank cell/value in another cell ...If cell value is greater than another cell value, clear contents ..... the value in cell G4. I just want to empty those cells ... Macro to clear contents of certain ... How to clear contents of a cell without removing the formula ...How to clear contents of a cell without removing the formula ... If cell value is greater than another cell value, clear contents ... > > > > > > > > > > I've found the ... See if cell value appears within a value range given by another ...If cell value is greater than another cell value, clear contents ... Range If Cell Value Is Greater Than ... ... within a value range given by another ... Delete cell value but keep formula in cell. - microsoft.public ...If cell value is greater than another cell value, clear contents ... I've found the below formula in one of the posts here ... clears out any dates which are greater than ... Return last and second last "populated" cell in column ...If cell value is greater than another cell value, clear contents ... Return last and second last "populated" cell in column ... If cell value is greater than another cell ... If cell value is greater than another cell value, clear contents ...Excel - If cell value is greater than another cell value, clear contents. If cell value is greater than another cell value, clear contents ...Okay, hopefully this is the last question today! I've found the below formula in one of the posts here, but my brain has completely failed on me ... Excel - Highlight Cell Based On Another Cells Value - Hello Im ...Condition 1: Cell Value is Greater Than E1....highlight ... of the cell itself and multiple values of another cell. ... cell in a row, based on the contents of another. Excel :: Extract Contents Of Cell If Greater Than Zero To A Comment... Contents Of Cell If Greater Than ... Value If Its Greater Then 0; Countif Forumla That Counts If One Cell Is Greater Than Another ... values they enter in a given row to the value ... How to Apply Conditional Formatting in Excel: 16 steps... the font or the font size of the contents in the cell. ... formatting based on the value of another cell or cells. ... like this: “When this cell’s value is greater than the ... 7/15/2012 3:57:41 PM
|