Populate to Last row - Simplify copy

Ananthak275

New Member
Joined
Aug 22, 2020
Messages
20
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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
651
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,549
Office Version
  1. 365
Platform
  1. Windows
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
 

Ananthak275

New Member
Joined
Aug 22, 2020
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
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?
 

Ananthak275

New Member
Joined
Aug 22, 2020
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

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
?
 

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
651

ADVERTISEMENT

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 '

 

Ananthak275

New Member
Joined
Aug 22, 2020
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,549
Office Version
  1. 365
Platform
  1. Windows
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:
 

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
651
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"?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,553
Messages
5,636,989
Members
416,953
Latest member
broexc

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
Top