![]() |
Excel/VBA - month dates
Hi there,
I am trying to develop something using VBA that says If the say B1 cell is greater than April then perform an action. B1 contains a date, say 01/08/03. I cant seem to get it to recognise that the month in B1 is greater than April? I can do it in excel but not using VBA code. Thanks alot Simon |
Excel/VBA - month dates
if Month(B1) 4 then
' greater than april if Month(B1) Month(DateSerial(Year(B1),4,1)) then ' greater than april -- Regards, Tom Ogilvy Simon wrote in message ... Hi there, I am trying to develop something using VBA that says If the say B1 cell is greater than April then perform an action. B1 contains a date, say 01/08/03. I cant seem to get it to recognise that the month in B1 is greater than April? I can do it in excel but not using VBA code. Thanks alot Simon |
Excel/VBA - month dates
Thank you Tom.
Sorry to bother you again. 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 -----Original Message----- Hi there, I am trying to develop something using VBA that says If the say B1 cell is greater than April then perform an action. B1 contains a date, say 01/08/03. I cant seem to get it to recognise that the month in B1 is greater than April? I can do it in excel but not using VBA code. Thanks alot Simon . |
Excel/VBA - month dates
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 -- Regards, Tom Ogilvy "Simon" wrote in message ... Thank you Tom. Sorry to bother you again. 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 -----Original Message----- Hi there, I am trying to develop something using VBA that says If the say B1 cell is greater than April then perform an action. B1 contains a date, say 01/08/03. I cant seem to get it to recognise that the month in B1 is greater than April? I can do it in excel but not using VBA code. Thanks alot Simon . |
All times are GMT +1. The time now is 10:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com