VBA Dates/Times - getting midnight???

combatvolcano

Board Regular
Joined
Jan 13, 2010
Messages
69
I have tried several ways of doing this...

I have a cell on the "settings" sheet which is a date time formatted as the *standard mm/dd/yyyy

I have tried either dim'ing my variable dd as date or not and assign it using
Code:
dd = sheets("settings").Range("b2").Value

I am trying to compare this to another date/time

When I use a msgbox to look at the other date/time I see a valid date/time in the msgbox (even when using DateValue() on it)

If I do the same thing to "dd" I get " 12:00:00 AM"

It seems this is actually the value because if I try DateDiff I get a huge -number????

Even this doesn't seem to work!

Code:
    ddy = Year(Sheets("SETTINGS").Range("B2").Value)
    ddm = Month(Sheets("SETTINGS").Range("B2").Value)
    ddd = Day(Sheets("SETTINGS").Range("B2").Value)
    dd = DateSerial(ddy, ddm, ddd)
    MsgBox (dd)
I am confused, I just want to compare two date/times in VBA to if one is greater! (and delete the row if it is lesser but I have a handle on that part)

thank you!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Which cell is it?

In your first few posts it was B2, then it changed to C2.:eek:

In your loop code what is ActiveCell?
 
Upvote 0

Forum statistics

Threads
1,224,874
Messages
6,181,511
Members
453,049
Latest member
amirrznjd

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