Populate to Last row - Simplify copy

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
Hey everyone,
My code goes into Column A, starts at row 2 and populates the values based on the last row in Column L.
1. I'm trying to make so instead of column B, it looks for the last row in the sheet, rather than a specific column.
2. Also is there a way to simplify it?

Populate_Column = "A"
DataStartRow = 2
LastRowColumn = “B"

Range(Populate_Column & DataStartRow).Select
Selection.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
ActiveCell.FormulaR1C1 = "=TODAY()"
Selection.NumberFormat = "yyyy/mm"
Selection.AutoFill Destination:=Range(Populate_Column & DataStartRow & ":" & Populate_Column & Range(LastRowColumn & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
just try this

VBA Code:
With Worksheets("sheet1")  ' You can change the sheet name
    With .Range("A2:A" & .Range("B" & .Rows.Count).End(xlUp).Row)
        .Formula = "=today()"
        '.Value = .Value
        .NumberFormat = "yyyy/mm"
     End With
End With
 
Upvote 0
How about
VBA Code:
Sub Ananthak()
   Dim UsdRws As Long
   
   UsdRws = Cells.Find("*", , , , xlByRows, xlPrevious, , False).Row
   With Range("A2:A" & UsdRws)
      .Formula = "=today()"
      .NumberFormat = "yyyy/mm"
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub Ananthak()
   Dim UsdRws As Long
  
   UsdRws = Cells.Find("*", , , , xlByRows, xlPrevious, , False).Row
   With Range("A2:A" & UsdRws)
      .Formula = "=today()"
      .NumberFormat = "yyyy/mm"
   End With
End Sub
Where do i specify the workbook and worksheets its in?
 
Upvote 0
just try this

VBA Code:
With Worksheets("sheet1")  ' You can change the sheet name
    With .Range("A2:A" & .Range("B" & .Rows.Count).End(xlUp).Row)
        .Formula = "=today()"
        '.Value = .Value
        .NumberFormat = "yyyy/mm"
     End With
End With
Why is there a " ' " before
.Value = .Value
?
 
Upvote 0
Why is there a " ' " before

?
it will convert the formula into values. like we do paste special values.
So '.vaule will keep the formula as it is.
and so if you want to keep it in values then just remove '

 
Upvote 0
it will convert the formula into values. like we do paste special values.
So '.vaule will keep the formula as it is.
and so if you want to keep it in values then just remove '
Hi, this worked perfect. i also have one more question. what if i set the date to a variable? seen below. how can i add this variable to be used instead of ".Formula" and "Number format"?

tdate = format(Date,"yy-dd"mm")

With Worksheets("sheet1") ' You can change the sheet name
With .Range("A2:A" & .Range("B" & .Rows.Count).End(xlUp).Row)
.Formula = "=today()"
'.Value = .Value
.NumberFormat = "yyyy/mm"
End With
End With
 
Upvote 0
You originally said
I'm trying to make so instead of column B, it looks for the last row in the sheet, rather than a specific column.
But the code from vmjan02 is still using column B to find the last row. Yet you say it works perfectly. :unsure:
 
Upvote 0
Thanks for the feed back and glade that it worked perfect for you

try this, and
VBA Code:
.NumberFormat = tdate

Hi, this worked perfect. i also have one more question. what if i set the date to a variable? seen below. how can i add this variable to be used instead of ".Formula" and "Number format"?
 
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,099
Members
448,548
Latest member
harryls

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