Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Range Selection

Hi,

I have a line of code :
Selection.AutoFill Destination:=Range("B2:B34461")

The number of rows refers to data which increases on a daily basis - I have
to manually increase the row number (e.g. B34461) each time the data
increases.

Is there a way I can change the line so it automatically picks up the last
row of the spreadsheet that has data on it ?

Many Thanks
Pete
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Range Selection

Hi
you can create a dynamic Range which increases in size automatically
In Excel click on the B2 cell (I assume B1 is a header?) of the sheet
(I'll call it Data) and type this in the refers to box:
=offset(Data!$B$2,0,0,COUNTA(Data!$B$B)-1,1)

and in the Names in workbook box type a name like myRange. Click Add
and OK.
Open the Insert name dialog box again and click the mouse inside this
formula - you should see a dotted line around your range, regardless of
how many new entries you add to the bottom.

Now your code becomes
Selection.AutoFill Destination:=Range("myRange")

I'm assuming here that there are no blank entries in myRange. If there
are, you will need a slightly different offset formula which will
depend on the location of the column with no blanks in it. Post back if
that is the case.
regards
Paul

Pete wrote:
Hi,

I have a line of code :
Selection.AutoFill Destination:=Range("B2:B34461")

The number of rows refers to data which increases on a daily basis - I have
to manually increase the row number (e.g. B34461) each time the data
increases.

Is there a way I can change the line so it automatically picks up the last
row of the spreadsheet that has data on it ?

Many Thanks
Pete


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Range Selection

Great !
Thanks Paul.

" wrote:

Hi
you can create a dynamic Range which increases in size automatically
In Excel click on the B2 cell (I assume B1 is a header?) of the sheet
(I'll call it Data) and type this in the refers to box:
=offset(Data!$B$2,0,0,COUNTA(Data!$B$B)-1,1)

and in the Names in workbook box type a name like myRange. Click Add
and OK.
Open the Insert name dialog box again and click the mouse inside this
formula - you should see a dotted line around your range, regardless of
how many new entries you add to the bottom.

Now your code becomes
Selection.AutoFill Destination:=Range("myRange")

I'm assuming here that there are no blank entries in myRange. If there
are, you will need a slightly different offset formula which will
depend on the location of the column with no blanks in it. Post back if
that is the case.
regards
Paul

Pete wrote:
Hi,

I have a line of code :
Selection.AutoFill Destination:=Range("B2:B34461")

The number of rows refers to data which increases on a daily basis - I have
to manually increase the row number (e.g. B34461) each time the data
increases.

Is there a way I can change the line so it automatically picks up the last
row of the spreadsheet that has data on it ?

Many Thanks
Pete



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
Narrow Range based on Selection in Another Range David Excel Discussion (Misc queries) 3 July 1st 07 05:12 PM
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
Range selection kirke Excel Programming 0 September 9th 06 07:15 AM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Creating range name for a range selection Mervyn Thomas Excel Programming 1 January 26th 04 05:18 PM


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