Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Pasting with Dynamic Last Row

I'm trying to paste a formula with a dynamic range, it could be 2000 rows to
10000 rows (see below). I tried defining LastRow using a Function but it
won't work. Anyone have a better way? The brute force alternative is to set
a large range, which works, but is messy because I want to then sort in a way
that leaves me with up to thousands of empty cells in the wrong place.

ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ActiveCell.Range("A1:A(LastRow)").Select
ActiveSheet.Paste


Thanks for any ideas.

Alan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Pasting with Dynamic Last Row

ActiveCell.Range("A1:A(LastRow)").Select

would raise an error. You would use

ActiveCell.Range("A1:A" & LastRow).Select

to find the last cell with date

lastrow = Cells(rows.count,2).End(xlup).Row

change 2 to match the column that will determine the extent of the data.

You can then just do
lastrow = Cells(rows.count,2).End(xlup).Row
Range("A1:A" & LastRow)..formula = range("A1").Formula


However, your recorded code is relative to the selection, so I don't know
where you actually are at that time. So the above might need to be modified.

--
Regards,
Tom Ogilvy


"Alan P" wrote in message
...
I'm trying to paste a formula with a dynamic range, it could be 2000 rows

to
10000 rows (see below). I tried defining LastRow using a Function but it
won't work. Anyone have a better way? The brute force alternative is to

set
a large range, which works, but is messy because I want to then sort in a

way
that leaves me with up to thousands of empty cells in the wrong place.

ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ActiveCell.Range("A1:A(LastRow)").Select
ActiveSheet.Paste


Thanks for any ideas.

Alan





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Pasting with Dynamic Last Row

Tom,

Thanks for your help, it was exactly what I needed. Works great.

Alan

"Tom Ogilvy" wrote:

ActiveCell.Range("A1:A(LastRow)").Select

would raise an error. You would use

ActiveCell.Range("A1:A" & LastRow).Select

to find the last cell with date

lastrow = Cells(rows.count,2).End(xlup).Row

change 2 to match the column that will determine the extent of the data.

You can then just do
lastrow = Cells(rows.count,2).End(xlup).Row
Range("A1:A" & LastRow)..formula = range("A1").Formula


However, your recorded code is relative to the selection, so I don't know
where you actually are at that time. So the above might need to be modified.

--
Regards,
Tom Ogilvy


"Alan P" wrote in message
...
I'm trying to paste a formula with a dynamic range, it could be 2000 rows

to
10000 rows (see below). I tried defining LastRow using a Function but it
won't work. Anyone have a better way? The brute force alternative is to

set
a large range, which works, but is messy because I want to then sort in a

way
that leaves me with up to thousands of empty cells in the wrong place.

ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ActiveCell.Range("A1:A(LastRow)").Select
ActiveSheet.Paste


Thanks for any ideas.

Alan






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
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Pasting on Filtered Data Sheets without pasting onto hidden cells CCSMCA Excel Discussion (Misc queries) 1 August 28th 05 01:22 PM
Pasting numbers and formulas without pasting format. Dan Excel Discussion (Misc queries) 3 March 27th 05 03:47 AM
Dynamic copying & pasting of rows Chris Bromley Excel Programming 7 February 8th 05 03:43 PM
Selecting & Pasting Dynamic Ranges GerryM[_2_] Excel Programming 4 November 17th 04 09:12 AM


All times are GMT +1. The time now is 07: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"