Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default using cell data to name a range

I have the following problem:
I have writen a macro that goes to the last row that contains data then
count up until it finds data in the first column (A). From this I have
the first row that contins data in the first column and the last row
that has data. I can now say that I have the C1Rx:C16Rx (the last
column with data always P).

What I need to do is take the info that is in C1Rx (its text) and name
the range.
From the macro recorder I get this


ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Sheet4!R2C1:R8C4"

But for the life of me I cant figure out how to use this to ad the name
and refer to the range correctly...

Something like this

ActiveWorkbook.Names.Add Name:= Range("A" & StartDataRow),
RefersToR1C1:=" =C1R(MyStartDataRow):R(LastDataRow)C16

I would greatly appreciate any help....

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default using cell data to name a range

Maybe like this (note the reference to the sheet name):

Dim rngName As String
rngName = Cells(StartDataRow, 1).Text
ActiveWorkbook.Names.Add Name:=rngName, _
RefersToR1C1:="=Sheet4!R" & StartDataRow & "C1:R" _
& LastDataRow & "C16"

Hope this helps
Rowan

Chris Salcedo wrote:
I have the following problem:
I have writen a macro that goes to the last row that contains data then
count up until it finds data in the first column (A). From this I have
the first row that contins data in the first column and the last row
that has data. I can now say that I have the C1Rx:C16Rx (the last
column with data always P).

What I need to do is take the info that is in C1Rx (its text) and name
the range.
From the macro recorder I get this


ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Sheet4!R2C1:R8C4"

But for the life of me I cant figure out how to use this to ad the name
and refer to the range correctly...

Something like this

ActiveWorkbook.Names.Add Name:= Range("A" & StartDataRow),
RefersToR1C1:=" =C1R(MyStartDataRow):R(LastDataRow)C16

I would greatly appreciate any help....

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default using cell data to name a range

This Works GREAT !!!!!!!

I have a question, does the sheet name have to be explicit?? Can it be
the active sheet ???

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default using cell data to name a range

Try:

rngName = Cells(StartDataRow, 1).Text
ActiveWorkbook.Names.Add Name:=rngName, _
RefersToR1C1:="=" & ActiveSheet.Name & "!R" & _
StartDataRow & "C1:R" & LastDataRow & "C16"

Regards
Rowan

Chris Salcedo wrote:
This Works GREAT !!!!!!!

I have a question, does the sheet name have to be explicit?? Can it be
the active sheet ???

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default using cell data to name a range

And if you are only going to be refering to the activesheet then more
simply:

Range(Cells(StartDataRow, 1), Cells(LastDataRow, 16)).Name _
= Cells(StartDataRow, 1).Value

Regards
Rowan

Chris Salcedo wrote:
This Works GREAT !!!!!!!

I have a question, does the sheet name have to be explicit?? Can it be
the active sheet ???



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default using cell data to name a range


Hi chris,

It looks like you want the range named after the top left cell.
see if there is anything here you can use.

http://vbaexpress.com/forum/showthread.php?t=5569

Dave

Chris Salcedo Wrote:
I have the following problem:
I have writen a macro that goes to the last row that contains data
then
count up until it finds data in the first column (A). From this I have
the first row that contins data in the first column and the last row
that has data. I can now say that I have the C1Rx:C16Rx (the last
column with data always P).

What I need to do is take the info that is in C1Rx (its text) and name
the range.
From the macro recorder I get this


ActiveWorkbook.Names.Add Name:="test",
RefersToR1C1:="=Sheet4!R2C1:R8C4"

But for the life of me I cant figure out how to use this to ad the
name
and refer to the range correctly...

Something like this

ActiveWorkbook.Names.Add Name:= Range("A" & StartDataRow),
RefersToR1C1:=" =C1R(MyStartDataRow):R(LastDataRow)C16

I would greatly appreciate any help....

Thanks



--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=474649

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
Last cell with data in a range iamjbunni Excel Worksheet Functions 7 March 26th 10 03:05 PM
find last cell in range with data, display cell address sevi61 Excel Worksheet Functions 14 October 29th 07 08:36 PM
How do I change cell color based upon data range within the cell? Chris Sanders Excel Worksheet Functions 1 March 6th 06 08:59 PM
Summed Cell won't update as I add data into the cell range... mrmer Excel Worksheet Functions 2 February 2nd 06 12:38 AM
How to enter data in one row cell only in a cell range Serge Excel Worksheet Functions 2 January 18th 06 07:03 PM


All times are GMT +1. The time now is 12:13 AM.

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"