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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Domski

Well-known Member
Joined
Jan 18, 2005
Messages
7,292
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

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,124
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

rubic

Active Member
Joined
Jul 9, 2008
Messages
251
Thanks guys, I will try these out and see which of these codes suit best to my need.
 
Upvote 0

rubic

Active Member
Joined
Jul 9, 2008
Messages
251
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,191,097
Messages
5,984,650
Members
439,898
Latest member
Zack0611

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
Top