[VBA] Date as serial appears in one cell, Americanised date in another.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
801
Office Version
  1. 365
Platform
  1. Windows
Hi all, same kind of issue as a few days ago..

Code:
NewIndate = Format(DateValue(InDate.Caption), "dd/mm/yyyy")NewOutdate = Format(DateValue(OutDate.Caption), "dd/mm/yyyy")


If NewIndate = "" And NewOutdate = "" Then


MsgBox "Please ensure you have entered a date or date range in the Control Panel", vbOKOnly, "ErRoR!"


Exit Sub
End If


Range("A1").Value = Format(DateValue(NewIndate), "dd/mm/yyyy")
Range("B1").Value = Format(DateValue(NewOutdate), "dd/mm/yyyy")

That's the code, values are entered in the Control panel like "01/09/2019" and "01/12/2019"

They should then be entered into cells A1 and B1 so I can return those values in the caption if I load the control panel again (that's sorted in a different part of code)


The problem is that for some unknown reason, the first date I enter "01/09/2019" (1st September) is stored in A1 as "43474" (9th Jan) and the second date I enter "01/12/2019" is stored in B1 as "12/01/2019"

Very frustrating, any ideas? I had just "Value = NewIndate" originally but it produced the same result.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Don't use Format when putting the dates into the cells, use DateValue and format the cell as required.
Code:
Range("A1").Value = DateValue(NewIndate)
Range("B1").Value = DateValue(NewOutdate)
 
Upvote 0
Don't use Format when putting the dates into the cells, use DateValue and format the cell as required.
Code:
Range("A1").Value = DateValue(NewIndate)
Range("B1").Value = DateValue(NewOutdate)


Thanks Norie, this sorted the problem :)
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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