VBA Date Format changed

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All,
for the past several months, I have been using the following code to insert a date or any missing dates:

VBA Code:
    If sht.Range("A" & iRow) <> Date Then
       iRow = iRow + 1
       sht.Range("A" & iRow) = Date
    End If

The date format, as set by windows 11 is dd-mm-yyyy - no probelm

But yesterday, because we have clicked over to the 1st Dec, the date is now being inserted as mm-dd-yyyy.

I don't understand why the format has changed.

I have tried to use various other format combinations, such as

sht.Range("A" & iRow).NumberFormat = "dd,mmm,yyyy", but in doing so, another test that checks that the last date in the table <> todays date now fails, resulting in
sht.Range("A" & iRow) = Date being added over and over again.

I can probably solve the inserting multiple times problem by copying the date format from the previous cell prior to doing test, but I would prefer to understand and fix this issue rather than put a bandaid on it.

Any direction is greatly appreciated.

thanks in advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You should only see the date format reversed if the cell is formatted to display it that way, or if it's formatted as text. Formatting an actual date cell in a different date format should not interfere with any comparison with a date value.
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

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