Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Copying range to variable number of rows

I have a number of worksheets (Sheets 1 to 4) with formulas in A2:J2.

These formulas need to be copied down to however many rows are populated in
Column A of another Sheet called Data.

So, if I import 140 rows of data into the Data sheet and run the macro the
formulas in Sheets 1 to 4 get copied from row 2 down to row 140, if I import
200 rows the formulas get copied to row 200 etc.

I'm struggling with this - probably because I'm using a variable (number of
rows) in another sheet rather than the equivalent of a shift-end-down-right
command.

Any help would be much appreciated

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copying range to variable number of rows

Hi nospaminlich

Try this

This example will filldown A2:J2 on "Sheet1" to row (row with last value
in Sheets "Data" in column A)

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

--
Regards Ron de Bruin
http://www.rondebruin.nl


"nospaminlich" wrote in message ...
I have a number of worksheets (Sheets 1 to 4) with formulas in A2:J2.

These formulas need to be copied down to however many rows are populated in
Column A of another Sheet called Data.

So, if I import 140 rows of data into the Data sheet and run the macro the
formulas in Sheets 1 to 4 get copied from row 2 down to row 140, if I import
200 rows the formulas get copied to row 200 etc.

I'm struggling with this - probably because I'm using a variable (number of
rows) in another sheet rather than the equivalent of a shift-end-down-right
command.

Any help would be much appreciated

Thank you



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Copying range to variable number of rows

That's brilliant Ron. Many thanks.
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
Copying a variable range of data from one worksheet to another. AllyB Excel Discussion (Misc queries) 3 March 2nd 09 11:37 PM
Macro for copying a value to a variable no. of rows Ian Grega Excel Discussion (Misc queries) 6 April 15th 08 02:48 PM
Copying RANGE of variable length Pele Excel Programming 2 October 19th 05 06:00 PM
Copying a variable range Brian Matlack[_9_] Excel Programming 6 October 17th 05 03:16 PM
count number of rows (variable range) Acid-Sky Excel Programming 3 August 23rd 05 10:06 AM


All times are GMT +1. The time now is 03:04 AM.

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"