View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Robert Hargreaves Robert Hargreaves is offline
external usenet poster
 
Posts: 18
Default If Statement problem

I am trying to set up an If statement and I am using a message box to test
if the code is working or not.

Following the Then in the If statement I will include a different range of
rows to be removed to take out 1 month from the beginning of the
spreadsheet.

My test code only gives a message box saying 1st January 2005 not feb march
etc. Why is this?

Here is my sheet

Row 1
Row 2
Row 3
01/01/2005
02/02/2005
03/02/2005
04/02/2005
05/02/2005
06/02/2005
.....
here is my code

If ActiveSheet.Range("$A$4").Value = #1/1/2005# Then
MsgBox ("The date is 1st Jan 2005"), vbInformation
ElseIf ActiveSheet.Range("$A$4") = #1/2/2005# Then
MsgBox ("The date is 1st Feb 2005"), vbInformation
ElseIf ActiveSheet.Range("$A$4") = #1/3/2005# Then
MsgBox ("The date is 1st Mar 2005"), vbInformation
ElseIf ActiveSheet.Range("$A$4") = #1/4/2005# Then

.....

it will look like this though when its working instead of testing...
If ActiveSheet.Range("$A$4").Value = #1/1/2005# Then
ActiveSheet.Rows("4:34").Delete
ElseIf ActiveSheet.Range("$A$4") = #1/2/2005# Then
ActiveSheet.Rows("4:31").Delete

Thanks for any suggestions

Rob