VBA - HOW TO: FILL A RANGE WITH FORMULA (LASTROW)

Опубликовано: 17 Октябрь 2024
на канале: Bored On A Tuesday
33,237
99

Kind of a terrible way of doing this but will do the trick in a bind



Sub Fill_Formula()
Dim rng As Range
Dim sht As Worksheet
Dim Lastrow As Long

Set sht = ThisWorkbook.Sheets("Sheet1") ' or Thisworkbook.Sheets(1)
Lastrow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 'Finds lastrow for column A,update to whichever one you need

Set rng = Range("C1:C" & Lastrow) 'Updating column C with formula, change to what you need
rng.Formula = "=RC[-2]+RC[-1]" 'Simple Formula, could be anything

End Sub