Help with codes

rubic

Active Member
Joined
Jul 9, 2008
Messages
251
I am trying to learn to write macro and I like to know how to correctly write the code if today date is more than 30 days compare to the date in cell D1 and if cell E1 is blank.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,

Something like:

Code:
Sub test()
 
With Sheets("Sheet1")
 
    If Date - .Range("D1").Value > 30 And .Range("E1") = "" Then
 
        MsgBox "Do some stuff!"
 
    End If
 
End With
 
End Sub

Hope it helps,

Dom
 
Upvote 0
not entirey sure I follow you...

do you mean

Code:
If DateDiff("d", CDate(Sheets("sheet1").Cells(4, 1)), Date) > 30 And Sheets("Sheet1").Cells(1, 5) = "" Then
    'do something if true
Else
    'do something else if not true
End If

(change "Sheet1" to your sheet name)
 
Upvote 0
Thanks guys, I will try these out and see which of these codes suit best to my need.
 
Upvote 0
Domski,

In your codes you have Date -.Range("D1").Value ....

I seem to run into a error problem with it. I am trying to compare the date in cell D1 with the system date which is the "today" date so to speak.


Please advice.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top