Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If cell value is greater than another cell value, clear contents.

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If cell value is greater than another cell value, clear conten

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default If cell value is greater than another cell value, clear conten

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If cell value is greater than another cell value, clear conten

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default If cell value is greater than another cell value, clear conten

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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default If cell value is greater than another cell value, clear conten

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Cell Contents based on Criteria of another cell CK Excel Programming 10 May 21st 09 04:07 PM
Macro to clear range contents when cell contents are changed by us Steve E Excel Programming 12 February 22nd 07 09:09 PM
how do i display cell contents greater than 255 characters in a t. Richard Lamey Excel Discussion (Misc queries) 1 February 13th 06 03:45 AM
VBA Clear Cell Contents towl[_3_] Excel Programming 4 October 20th 05 05:14 PM
Type into one cell and automatically clear contents in another cell Bo Excel Programming 4 September 29th 03 06:04 PM


All times are GMT +1. The time now is 10:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"