VBA - programming months

S

Simon

Hi there,.

I now have something like this but it is not working
correctly. Any ideas?

In column E cells have the word network in them
In column F (c.Offset(0, 1)) there is various dates

I am trying to compare these dates in column F (months) to
see if they are greater than April.

I need to use the offset function since the lines will
always change.

Here it is.

Dim MyDate, MyMonth
MyDate = Month(MyMonth)

For Each c In Range("E1:E20")
MyMonth = c.Offset(0, 1)

If c.Value = "network" Then
If MyDate > Month(DateSerial(2003, 4, 1)) Then

c.Offset(0, -4) = "yes"

Else

c.Offset(0, -4) = "no"

End If
End If

Next
End Sub

Thanks again

Simon
 
B

Bill Li

Hi Simon,

Seems your seq has problem. Try

For Each c In Range("E1:E20")
MyMonth = c.Offset(0, 1)
MyDate = Month(MyMonth)
...
Next

Best Regards

Bill
 
T

Tom Ogilvy

Here is last night's answer

Dim MyDate as Date

For Each c In Range("E1:E20")
MyDate = c.Offset(0, 1)


If c.Value = "network" Then
If Month(MyDate) > 4 Then

c.Offset(0, -4) = "yes"

Else

c.Offset(0, -4) = "no"

End If
End If

Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top