Date as serial number in vba

dcdc#1

New Member
Joined
Oct 2, 2007
Messages
19
Hi

I'm finally getting there...

Can anyone tell me how to convert a date (in standard dd/mm/yy format) to its equivalent Excel serial number? I'm trying to do an application.hlookup and it's only working if I enter the serial number directly rather than using the formatted date.

TIA
Danny
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
this is interesting as I need to do almost the same thing.

Except in VBA I'm trying to find a week commencing date for the current date (i.e. whatever today's "day", the value returned would always be the preceding sunday).

I'm trying to use...

wc_date = CLng(Date - Weekday(Date, vbSunday) - 7)

The only reason I'm using "CLng" is that when I use...

wc_date = Date - Weekday(Date, vbSunday) - 7

...and then try to find wc_date within a range of cells formatted as "dd/mm/yyyy" on the sheet itself, they're not being found (even if I declare wc_date as a variant, so it resolves as a variant/date to match the variant/dates held on the sheet).

Preferably, I'd be able to work out why, without using CLng, it can't find the date on the sheet but if the not finding in this case is a known feature, I'll settle for any help I can get.

Thanks.
 
Last edited:
Upvote 0
Asterix

How have you declared wc_date?

If you've declared it as Integer then that could be the problem.

Integers can only store values from 32,768 to 32,767.

So the last date an integer can store is 16th September 1989.

Try declaring as Long.
 
Upvote 0
this is interesting as I need to do almost the same thing.

Except in VBA I'm trying to find a week commencing date for the current date (i.e. whatever today's "day", the value returned would always be the preceding sunday).

I'm trying to use...

wc_date = CLng(Date - Weekday(Date, vbSunday) - 7)

The only reason I'm using "CLng" is that when I use...

wc_date = Date - Weekday(Date, vbSunday) - 7

...and then try to find wc_date within a range of cells formatted as "dd/mm/yyyy" on the sheet itself, they're not being found (even if I declare wc_date as a variant, so it resolves as a variant/date to match the variant/dates held on the sheet).

Preferably, I'd be able to work out why, without using CLng, it can't find the date on the sheet but if the not finding in this case is a known feature, I'll settle for any help I can get.

Thanks.

Thanks, answered my own question (with a little embarrasment on the way - it helps if you don't CLng a dim'd integer:LOL:)
 
Upvote 0
Asterix

How have you declared wc_date?

If you've declared it as Integer then that could be the problem.

Integers can only store values from 32,768 to 32,767.

So the last date an integer can store is 16th September 1989.

Try declaring as Long.

"On the money" and your post didn't show up for me until 1723hrs GMT (despite refreshing)
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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