Autofill Date Macro

ladylissa21

New Member
Joined
Feb 23, 2015
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi! I'm trying my hand at editing a macro I recorded, and not having much luck. I just need to find a way to autofill the date just down to the last populated row instead of to the bottom of the page. Here's the pertinent section:

Columns("C:C").Select
Selection.InsertShift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.NumberFormat = "mm/dd/yy"
Range("C1").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Range("C1").Select
Selection.AutoFillDestination:=Range("C:C")
Range("C:C").Select
Cells.Select
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You can look at column B to find the last row with data, and then populate column C down to that row with your formula, i.e.
Code:
    Dim lRow As Long
'   Find last row in column B with data
    lRow = Cells(Rows.Count, "B").End(xlUp).Row
'   Fill column C with current date
    Range("C1:C" & lRow).Formula = "=TODAY()"
Note: The code above only addresses the autofill part, and does not include the column insert and formatting, since that part was not problematic for you.
 
Last edited:
Upvote 0
Try
Code:
Columns("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("C:C").NumberFormat = "mm/dd/yy"
Range("C1", Range("A" & Rows.Count).End(xlUp).Offset(, 2)).Value = "=TODAY()"
This uses col A to find the last row
 
Upvote 0
Joe4 this worked perfectly! Thank you so much for the fast help!
 
Last edited:
Upvote 0
You are welcome.

Note that the first two lines of Fluff's post show you how you reduce that part from 3 lines down to 2, and also avoids using any "Select" statements, which helps speed up code performance.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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