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

Hi,

I have a sheet which is updated whenever workbook is opened. What I need to
do is update named ranges. As you can see in the code below, the code still
refers to R number. But when the workbook is updated the last row might
R1327, which I need to include. So basically how can I create a code that
helps me with dynamic ranges. Note: I tried using reference
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536;COUNTA(Sheet1! $A:$A);COUNTA(Sheet1!$1:$1))
which worked fine in the past, but as I use a sumproduct function in the
workbook I cannot include cells that are blank (so it seems).


Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersToR1C1:= _
"='Source Data'!R2C7:R1314C7"

Kind regards,

Basta
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Name a variable range

'Last filled row in Column A
lngLastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row

OR

Dim rngData As Range
Set rngData = Range("A1", Cells(Rows.Count, "A").End(xlUp))
MsgBox rngData.Address

If this post helps click Yes
---------------
Jacob Skaria


"Basta1980" wrote:

Hi,

I have a sheet which is updated whenever workbook is opened. What I need to
do is update named ranges. As you can see in the code below, the code still
refers to R number. But when the workbook is updated the last row might
R1327, which I need to include. So basically how can I create a code that
helps me with dynamic ranges. Note: I tried using reference
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536;COUNTA(Sheet1! $A:$A);COUNTA(Sheet1!$1:$1))
which worked fine in the past, but as I use a sumproduct function in the
workbook I cannot include cells that are blank (so it seems).


Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersToR1C1:= _
"='Source Data'!R2C7:R1314C7"

Kind regards,

Basta

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Name a variable range

rather tahn VBA, just make the range dynamic?

in Insert/Name/Define
select dates then set the refers to:

=OFFSET(Sheet1!IR1,0,0,COUNTA(Sheet1!IR:IR),2)

once done the range will grow/shrink depending on the number of items in
column A....BUT beware, there must be no gaps




"Basta1980" wrote:

Hi,

I have a sheet which is updated whenever workbook is opened. What I need to
do is update named ranges. As you can see in the code below, the code still
refers to R number. But when the workbook is updated the last row might
R1327, which I need to include. So basically how can I create a code that
helps me with dynamic ranges. Note: I tried using reference
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536;COUNTA(Sheet1! $A:$A);COUNTA(Sheet1!$1:$1))
which worked fine in the past, but as I use a sumproduct function in the
workbook I cannot include cells that are blank (so it seems).


Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersToR1C1:= _
"='Source Data'!R2C7:R1314C7"

Kind regards,

Basta

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Name a variable range

Hi Patrick,

I'm not only one working with workbook. Therefore I want to automate it.

Regards,

Basta

"Patrick Molloy" wrote:

rather tahn VBA, just make the range dynamic?

in Insert/Name/Define
select dates then set the refers to:

=OFFSET(Sheet1!IR1,0,0,COUNTA(Sheet1!IR:IR),2)

once done the range will grow/shrink depending on the number of items in
column A....BUT beware, there must be no gaps




"Basta1980" wrote:

Hi,

I have a sheet which is updated whenever workbook is opened. What I need to
do is update named ranges. As you can see in the code below, the code still
refers to R number. But when the workbook is updated the last row might
R1327, which I need to include. So basically how can I create a code that
helps me with dynamic ranges. Note: I tried using reference
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536;COUNTA(Sheet1! $A:$A);COUNTA(Sheet1!$1:$1))
which worked fine in the past, but as I use a sumproduct function in the
workbook I cannot include cells that are blank (so it seems).


Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersToR1C1:= _
"='Source Data'!R2C7:R1314C7"

Kind regards,

Basta

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Name a variable range

Hi Patrick,

I'm not only one working with workbook. Therefore I want to automate it.

Regards,

Basta

"Patrick Molloy" wrote:

rather tahn VBA, just make the range dynamic?

in Insert/Name/Define
select dates then set the refers to:

=OFFSET(Sheet1!IR1,0,0,COUNTA(Sheet1!IR:IR),2)

once done the range will grow/shrink depending on the number of items in
column A....BUT beware, there must be no gaps




"Basta1980" wrote:

Hi,

I have a sheet which is updated whenever workbook is opened. What I need to
do is update named ranges. As you can see in the code below, the code still
refers to R number. But when the workbook is updated the last row might
R1327, which I need to include. So basically how can I create a code that
helps me with dynamic ranges. Note: I tried using reference
=Sheet1!$A$1:INDEX(Sheet1!$1:$65536;COUNTA(Sheet1! $A:$A);COUNTA(Sheet1!$1:$1))
which worked fine in the past, but as I use a sumproduct function in the
workbook I cannot include cells that are blank (so it seems).


Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="dates", RefersToR1C1:= _
"='Source Data'!R2C7:R1314C7"

Kind regards,

Basta

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
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


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