Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Redefining a new Range area

Hi Folks,
I'm creating a macro where, each time it's run, I have to delete and
redefine a range (called List) which keeps growing.

I recorded it as follows:-
ActiveWorkbook.Names("List").Delete
Sheets("Database").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="List", RefersToR1C1:= _
"=Database!R1C1:R3781C6"

In the macro, the range is fixed at row 3781, but of course this will grow.

Is there some VBA code I can plug in which will select the entire range,
redefining the size as the range grows?

Thanks,

Paul Silverman
Melbourne Australia


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Redefining a new Range area

Paul

The code below will define a dynamic range and name it 'List'. There is
seldom any need to select anything but as that was what you requested that
is included. (This results in the code to activate the sheet as you can
select a range on a sheet that is not activated).

Sub redefineRange()
Dim lLastRow As Long
Dim iLastColumn As Integer
ThisWorkbook.Names("List").Delete
With Worksheets("Database")
lLastRow = .Range("A65536").End(xlUp).Row
iLastColumn = .Range("IV1").End(xlToLeft).Column
.Activate
End With
Range(Cells(1, 1), Cells(lLastRow, iLastColumn)).Select
ThisWorkbook.Names.Add Name:="List", RefersToR1C1:=Selection
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Paul Silverman" wrote in message
...
Hi Folks,
I'm creating a macro where, each time it's run, I have to delete and
redefine a range (called List) which keeps growing.

I recorded it as follows:-
ActiveWorkbook.Names("List").Delete
Sheets("Database").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="List", RefersToR1C1:= _
"=Database!R1C1:R3781C6"

In the macro, the range is fixed at row 3781, but of course this will
grow.

Is there some VBA code I can plug in which will select the entire range,
redefining the size as the range grows?

Thanks,

Paul Silverman
Melbourne Australia




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Redefining a new Range area

Hi Paul,

Try:

Sub Tester()
With ActiveWorkbook
.Names.Add Name:="List", RefersToR1C1:=.Sheets("Database"). _
Range("A1").CurrentRegion
End With
End Sub

---
Regards,
Norman



"Paul Silverman" wrote in message
...
Hi Folks,
I'm creating a macro where, each time it's run, I have to delete and
redefine a range (called List) which keeps growing.

I recorded it as follows:-
ActiveWorkbook.Names("List").Delete
Sheets("Database").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="List", RefersToR1C1:= _
"=Database!R1C1:R3781C6"

In the macro, the range is fixed at row 3781, but of course this will
grow.

Is there some VBA code I can plug in which will select the entire range,
redefining the size as the range grows?

Thanks,

Paul Silverman
Melbourne Australia




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
SUMIF with area that is not a range lwsnbaker Excel Worksheet Functions 2 March 12th 10 03:49 PM
Redefining the $ icons format todd Excel Worksheet Functions 5 September 6th 08 11:10 PM
Print area/range Mike D. Excel Discussion (Misc queries) 2 June 30th 05 07:07 PM
Redefining Styles Grant Reid Excel Programming 1 July 19th 04 02:10 PM
Find Used area of a range MDW[_2_] Excel Programming 2 February 18th 04 02:08 AM


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