Enter Date

tracktor

Board Regular
Joined
Sep 13, 2009
Messages
62
When I press a control button I want a macro to run a routine and enter todays date (and time) in column AI at the end of each row that doesn't already have the date in it. I am using the =Now() formula with the following routine. The date is static once it is entered at the end of the row, because I copy and paste just the values.

Sub Date ()
'Copy the =Now()formula
Range("AI1").Select
Selection.Copy
'Select a column with data in it to find the last row
Range("G3").Select
Selection.End(xlDown).Select
'Move the active cell over 28 cells and up 1 to get to the bottom of column AI
Selection.Offset(-1, 28).Select
'Select the empty cells at the bottom of the column minus the header
Range(Selection, Selection.End(xlUp)).Select
Selection.Offset(1, 0).Select
'Paste the formula to the empty cells
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

It works but I know there is an easier way that isn't so cumbersome.

Thanks in advance
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I can't follow what your code is doing at all but I would have done it like this:-
Code:
Option Explicit
 
Public Sub InsertDates()
 
  Dim iLast As Long
  Dim iRow As Long
  
  With ThisWorkbook.Sheets("Sheet1")
    iLast = .Cells(Rows.Count, 7).End(xlUp).Row
    For iRow = 1 To iLast
      If IsEmpty(.Range("AI" & iRow)) Then
        .Range("AI" & iRow) = Format(Now(), "dd-mmm-yyyy hh:nn:ss")
      End If
    Next iRow
  End With
 
End Sub
 
Upvote 0
There's seldom any need to use .Select to move around the workbook if yoiu can address ranges explicitly.
 
Upvote 0
This code only fills in the date in the last cell in the column at the end of the data. I import anywhere from 100 to several thousand records at a time. I need the date on each row with each record.
 
Upvote 0
I cant seem to get this to work within another routine that I am trying to nestle it in. It works fine on it's own. I don't know much about coding other than copy and paste.
 
Upvote 0
I would have replied to any of those posts but I couldn't get a word in edgeways! :)

Glad you're sorted now though.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,360
Members
449,155
Latest member
ravioli44

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