Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Today`s date in an excel macro

Tags:

excel

vba

I am trying to add today's date to column A in sheet2. Each time my macro pastes my selection in sheet1, column B, to a new row in sheet2.

My script works to add the new row and paste my selection in sheet2, but I can't figure out how I should get the date in column A for the new row in sheet2. Here is the script in my macro;

Sub move()  
        Dim i As Integer 
        Application.ScreenUpdating = False
        ActiveWorkbook.Sheets("Sheet1").Range("A1,A2,A3,A4,A5").Copy
       
        Sheets("Sheet2").Select
        i = 3
        While Range("B" & i).Value <> ""
            i = i + 1
        Wend
        Range("B" & i).Select
   
        Selection.PasteSpecial (xlValues), Transpose:=True
 
        Worksheets("Sheet1").Range("A1:A5").Clear
 
End Sub
like image 468
G M Avatar asked Oct 24 '13 20:10

G M


People also ask

How do I create a macro today's date in Excel?

Value = Format(Now(),"MM/DD/YYYY") . Modify as needed.

How do I get today's date in Excel?

To insert today's date in Excel you simply type “=today” in the cell and then open and close brackets “()” with nothing in between them.

Which function is used to display today's date in VBA?

This example uses the Now function to return the current system date and time. Dim Today Today = Now ' Assign current system date and time.

How do I get the current date and time in Excel VBA?

The Microsoft Excel NOW function returns the current system date and time. The NOW function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a worksheet function (WS) and a VBA function (VBA) in Excel.


1 Answers

Try the Date function. It will give you today's date in a MM/DD/YYYY format. If you're looking for today's date in the MM-DD-YYYY format try Date$. Now() also includes the current time (which you might not need). It all depends on what you need. :)

like image 94
ARich Avatar answered Sep 28 '22 07:09

ARich