Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Name a range with relative reference

How to create name using relative reference? The table will be use in a Pivot
Table later in the macro. This is why I need to name a table.
The table, change size everytime we extract this from a database.
The macro is in the Personnal Macro to be use with many files.
Right now the name is create, however I am missing some data when the table
change size. The macro doesn't go under row 55
I tried different ways and nothing work.
Rules:
The table always start at cell: A4
Column A always have data and I use this one to trigger the last row of the
table.
# Of Rows change all the time.
The last column is always: J
Sometimes the last cells in column J do not have data
Here what I did the last time

Range("A4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="HvacTable", RefersToR1C1:= _
"=Sheet1!R4C1:R55C12"
ActiveCell.Select

Thank you very much

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Name a range with relative reference

Range("A4").Select
Set MyRange = Range(Selection, ActiveCell.SpecialCells(xlLastCell))
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="HvacTable", RefersToR1C1:= _
"=" & MyRange.Address


"Mouimet" wrote:

How to create name using relative reference? The table will be use in a Pivot
Table later in the macro. This is why I need to name a table.
The table, change size everytime we extract this from a database.
The macro is in the Personnal Macro to be use with many files.
Right now the name is create, however I am missing some data when the table
change size. The macro doesn't go under row 55
I tried different ways and nothing work.
Rules:
The table always start at cell: A4
Column A always have data and I use this one to trigger the last row of the
table.
# Of Rows change all the time.
The last column is always: J
Sometimes the last cells in column J do not have data
Here what I did the last time

Range("A4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="HvacTable", RefersToR1C1:= _
"=Sheet1!R4C1:R55C12"
ActiveCell.Select

Thank you very much

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Name a range with relative reference

Dim myRng as range
Dim LastRow as range

with worksheets("somesheetnamehere")
lastrow = .cells(.rows.count,"A").end(xlup).row
set myrng = .range("A4:J" & lastrow)
myrng.name = "HvacTable"
end with

You may want to drop the name stuff from your code and use a dynamic range name.

Assuming that there is always something in A1:A3 (even a formula that makes the
cell look empty, like: =""), you could use:

=OFFSET(Sheet1!$A$4,0,0,COUNTA(Sheet1!$A:$A)-3,10)

(change the sheet name as required (twice).)

Debra Dalgleish explains dynamic range names he
http://contextures.com/xlNames01.html#Dynamic



Mouimet wrote:

How to create name using relative reference? The table will be use in a Pivot
Table later in the macro. This is why I need to name a table.
The table, change size everytime we extract this from a database.
The macro is in the Personnal Macro to be use with many files.
Right now the name is create, however I am missing some data when the table
change size. The macro doesn't go under row 55
I tried different ways and nothing work.
Rules:
The table always start at cell: A4
Column A always have data and I use this one to trigger the last row of the
table.
# Of Rows change all the time.
The last column is always: J
Sometimes the last cells in column J do not have data
Here what I did the last time

Range("A4").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
ActiveWorkbook.Names.Add Name:="HvacTable", RefersToR1C1:= _
"=Sheet1!R4C1:R55C12"
ActiveCell.Select

Thank you very much


--

Dave Peterson
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
Relative Range Reference in a sumifs formula cbotos Excel Worksheet Functions 6 April 1st 10 02:59 AM
Range of cells: Convert relative reference into absolute Igor Excel Discussion (Misc queries) 5 September 30th 08 01:16 AM
Macro using relative cell reference to set name for range Sandy Excel Programming 4 May 30th 08 03:30 PM
Using Relative Reference Function to apply to Range Anthony[_14_] Excel Programming 2 December 14th 06 03:00 AM
Range.FormulaArray drops relative reference ? SPaquin Excel Programming 4 September 13th 05 03:00 AM


All times are GMT +1. The time now is 04:30 PM.

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

About Us

"It's about Microsoft Excel"