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

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
375
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,361
Office Version
365
Platform
Windows
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)
 

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
375
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 :)
 

Forum statistics

Threads
1,081,423
Messages
5,358,595
Members
400,505
Latest member
JacquiT

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top