Copy formula down variable rows based on (lastrow) from another sh

A

adidas12121

I have a variable number of rows in Sheet1, starting on row 2 ( Row 1
contains a column header ). Lets say for example this time it is 500 rows. (
lastrow = 501 ). On Sheet 2 I have a column header in cell a1 and an
existing formula in A2. How do I copy the formula down based on the lastrow
value from Sheet 1. In this example, the macro would copy the formula down
to A501.

Thanks in advance for your help,
Joe
 
R

Ron de Bruin

Basic code looks like this

Sub test()
Dim LastRow As Long
With Worksheets("Sheet2")
LastRow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
.Range("A2").AutoFill Destination:=.Range("A2:A" & LastRow) _
, Type:=xlFillDefault
End With
End Sub
 
D

Dave Peterson

Dim LastRow as long
with worksheets("Sheet1")
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("A2:A" & lastrow).formular1c1 _
= worksheets("Sheet2").range("a2").formular1c1
end with

But if you use column A to find the last row, then aren't you overwriting the
stuff in that range?
 
A

adidas12121

Hi Ron,
PERFECT Solution !
Your code worked perfect the very first time I used it.
Thank you very much for saving me so much time, I appreciate it
Have a great day,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top