Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy formula down variable rows based on (lastrow) from another sh

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy formula down variable rows based on (lastrow) from another sh

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" wrote in message ...
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy formula down variable rows based on (lastrow) from another sh

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy formula down variable rows based on (lastrow) from anothe

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" wrote in message ...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide rows in an Excel worksheet based on a variable Dave Osborn Excel Discussion (Misc queries) 2 July 21st 09 10:11 PM
Copy&Paste variable range based on cell value Thomas Excel Programming 0 July 27th 07 06:40 PM
Copy rows to new sheet based on variable cell reference michaelberrier Excel Programming 1 December 26th 06 04:21 PM
Copy Formula loop based on number of rows w/ data in a col B. Bernie Deitrick Excel Programming 1 August 20th 04 10:17 PM
Using the Lastrow variable in a Count/Countif formula John[_80_] Excel Programming 2 April 17th 04 03:44 AM


All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"