Sunday, 16 July 2017

excel - How do i create a macro to autofill data from the top row down to the last adjacent column with data in it?

I need to create a macro that can take data in columns F through I and autofill it down to the last cell in column E that has data in it. The code below almost does what I need it to do. However, I want to be able to use this macro with different data further down in columns F:I. How can i do this?



Dim lastrow As Long




lastrow = Range("e" & Rows.Count).End(xlUp).Row



Dim x(1 To 4) As Variant



With ThisWorkbook.Sheets("sheet1")
x(1) = Range("f2")
x(2) = Range("g2")
x(3) = Range("H2")
x(4) = Range("I2")


.Range("F3:i3").Formula = x
.Range("f3:i" & lastrow).FillDown


End With

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...