(Solved) – How to add Date every day to my first blank row in Excel with VBA


I would like every day, when I open excel, that my excel would add a today’s date to it. I have this code, but it isn’t working, sometimes it does what it’s supposed to and sometimes it skips a line, any help please?

Sub Stretching()
'This procedure will run each time you open the workbook

   'Specify the required worksheet name in double quotes
    Dim ws As Worksheet
    Set ws = Sheets("Stretching")

    'Get the last row number filled with a value in Column A
    Dim lastRow As Long
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row

    'Check if the last entered date is the same as the current date, if so, exit
    'You need this check to see if you close the workbook then open it on the same day
    'so that the code does not enter the same date again in a new row.
    If ws.Cells(lastRow, 1).Value = Date Then Exit Sub

    'Fill a new row in Column A with the current date
    If IsEmpty(Cells(lastRow, 1)) Then
        ws.Cells(lastRow, 1).Value = Date
        ws.Cells(lastRow, 1).Offset(1, 0).Value = Date

    End If
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *