Forum Discussion
dufusgoofus
Oct 10, 2022Copper Contributor
Help with selecting dynamic last cell in column and apply formula to rows below it
Hi. VBA and Macro noob here. Need help, please. I have a workbook that pulls order details from multiple worksheets into columns A to T, where column A is the order number and column K and Q are alw...
ITTom365
Oct 10, 2022Brass Contributor
not sure I,ve entirely understood your question; however assuming the following columns are what yor describing, the VBA below will fill cells "b3:b9" with your formula
| Orders (Col A) | Formulas (Col B) |
| 1 | notEmpty |
| 2 | notEmpty |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 |
Sub getLastRows()
Dim ws As Worksheet
Set ws = Sheets("mySheet")
Dim aLastRow As Long
aLastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
Dim bLastRow As Long
bLastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
Dim myFillRange As Range
Set myFillRange = ws.Range("B" & bLastRow + 1 & ":B" & aLastRow)
myFillRange.FormulaR1C1 = _
"=1+1"
End Sub
hope it helps or gives you a lead