PC Review


Reply
Thread Tools Rate Thread

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

 
 
adidas12121
Guest
Posts: n/a
 
      23rd Oct 2008
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
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      23rd Oct 2008
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


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"adidas12121" <(E-Mail Removed)> wrote in message news:09B20015-E122-4A36-94B6-(E-Mail Removed)...
>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

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Oct 2008
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?


adidas12121 wrote:
>
> 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


--

Dave Peterson
 
Reply With Quote
 
adidas12121
Guest
Posts: n/a
 
      23rd Oct 2008
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

"Ron de Bruin" wrote:

> 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
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "adidas12121" <(E-Mail Removed)> wrote in message news:09B20015-E122-4A36-94B6-(E-Mail Removed)...
> >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

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting and copying Rows based on a variable Darwin Microsoft Excel Programming 2 25th Sep 2009 10:33 AM
Delete Rows based on # of rows (no variable?) DanaK Microsoft Excel Programming 7 3rd Nov 2008 12:11 AM
Copy rows to new sheet based on variable cell reference michaelberrier Microsoft Excel Programming 1 26th Dec 2006 04:21 PM
Re: Copy Formula loop based on number of rows w/ data in a col B. Bernie Deitrick Microsoft Excel Programming 1 20th Aug 2004 10:17 PM
Using the Lastrow variable in a Count/Countif formula John Microsoft Excel Programming 2 17th Apr 2004 03:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:18 AM.