Changing date format in a macro

sncb

Board Regular
Joined
Mar 17, 2011
Messages
168
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi All,

My macro currently pastes dates in column 'G' with format mm/dd/yy and I need to change it to dd/mm/yy.

Can anyone suggest the line of code required.

Here is the current code:

If

Cells(IntCounter, 6).Value = "No" Then
If IsError(Application.Match(Cells(IntCounter, 2), Sheets("Test").Columns("B"), 0)) Then
Rows(IntCounter).Cut Destination:=Sheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets("Test").Range("G" & Rows.Count).End(xlUp).Offset(1).Value = Date

End If


Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The Format function returns a string. Try:

Code:
With Sheets("Test").Range("G" & Rows.Count).End(xlUp).Offset(1)
    .NumberFormat = "dd/mm/yyyy"
    .Value = Date
End With
 
Upvote 0
Hi,

For some reason the first code worked and I was able to see the dates in dd/mm/yyyy format. The second one was giving me a syntax error.

Others Thanks as well.
 
Upvote 0
With James' code I think you will find that the date is text, not a serial date. You can check with the ISNUMBER function - returns TRUE for a serial date.

Which line of my code caused a compile error? It compiles fine for me.
 
Upvote 0
Hi Andrew,,

my mistake..I didnt start and end with the 'With' operator...it ran fine...Thanks a lot..
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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