PDA

View Full Version : VBA: Copy row to the last line of data



Teatimedgg
10-03-2017, 01:32 PM
Hi everyone, Still new! but learning with everyone's help :-)

I have data in columns D and G and I am adding a formula in Columns A, B, C, E, F and J. I want to make sure the formula columns go to the end of the data in Column D when I copy it down.

Example:

See attached

I want columns to use column D to know where to copy the formula down to.


thanks!!

Bob Phillips
10-03-2017, 02:17 PM
Something like


Dim lastrow As Long

With ActiveSheet

lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
.Cells(3, "A").Resize(lastrow - 2).Formula = "=myformula1"
.Cells(3, "B").Resize(lastrow - 2).Formula = "=myformula2"
'etc
End With

mdmackillop
10-03-2017, 03:00 PM
Sub Test()
Dim lastrow As Long
Dim Arr, a
Arr = Array("A", "B", "C", "E", "F", "J")
With ActiveSheet
lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
For Each a In Arr
.Cells(3, a).Resize(lastrow - 2).FillDown
Next a
End With
End Sub

Teatimedgg
10-04-2017, 08:05 AM
Thank you!!

mdmackillop
10-04-2017, 08:20 AM
If this is answered please mark it so using Thread Tools dropdown.