Excel Date format

bulevardi

Board Regular
Joined
Apr 21, 2011
Messages
69
I have an input form that adds data to a table with some calculations.
One of the things my VBA script does is adding a date to that table for each entry aswel.

Now, the date format I used in the column is "dd/mm/yyy"
So today on 1st of september, it should write:
01/09/2011

But it always keeps me showing up:
09/01/2011

The function I have in the VBA script to create the date is:
Code:
Function DateAndTime()
 DateAndTime = Now
 DateAndTime = Format(DateAndTime, "dd/mm/yyyy")
  With Selection
   .Copy
   .PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  End With
 Application.CutCopyMode = False
End Function
Can someone help me with this?
I assume it's a commen problem?... I'm quite new to this.

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi

Try the following:

Select a cell and run:

Code:
Function DateAndTime()
Dim dtDateAndTime As Date
 
 dtDateAndTime = Now
 Selection.NumberFormat = "dd/mm/yyyy"
 Selection.Value = dtDateAndTime
End Function
 
Upvote 0
Not really no, there's no selection made.

Code:
With Sheets("Another Sheet")
    nextrow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
    .Cells(nextrow, 1) = DateAndTime()
End With


With the following code, he puts the date in cell on a wrong sheet:
Code:
Function DateAndTime() Dim dtDateAndTime As Date    dtDateAndTime = Now  Selection.NumberFormat = "dd/mm/yyyy"  Selection.Value = dtDateAndTime End Function</pre>
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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