Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Multiple Dynamic Named Ranges across Columns

Hi all. I have been using the following formula to create dynamic named ranges:
=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A),1)

Where A1 is the column header of the data to be included in the named range.

Now I need to create dynamic named ranges from Column A thru Column CK. Is there a way to do this with code so I don't have to manually create each one? The data in row 1 is what I would like the name of the range to be.

Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Multiple Dynamic Named Ranges across Columns

On Monday, July 30, 2012 6:17:45 PM UTC-5, Steve wrote:
Hi all. I have been using the following formula to create dynamic named ranges:

=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A),1)



Where A1 is the column header of the data to be included in the named range.



Now I need to create dynamic named ranges from Column A thru Column CK. Is there a way to do this with code so I don't have to manually create each one? The data in row 1 is what I would like the name of the range to be.



Thanks in advance!


Should do it
Sub MakeColumnDefinedNamesSAS()
Dim i As Long
Dim lr As Long
For i = 1 To 89
lr = Cells(Rows.Count, i).End(xlUp).Row
Range(Cells(1, i), Cells(lr, i)).Name = "col" & i
Next i
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Multiple Dynamic Named Ranges across Columns

Hi Steve,

Am Mon, 30 Jul 2012 16:17:45 -0700 (PDT) schrieb Steve:

Hi all. I have been using the following formula to create dynamic named ranges:
=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A),1)

Where A1 is the column header of the data to be included in the named range.

Now I need to create dynamic named ranges from Column A thru Column CK. Is there a way to do this with code so I don't have to manually create each one? The data in row 1 is what I would like the name of the range to be.


your first name is "Test". If not, change it in the code:

Sub myNames()
Dim LCol As Integer
Dim i As Integer

LCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To LCol
ActiveWorkbook.Names.Add Name:=Cells(1, i), _
RefersTo:="=OFFSET(Test,," & i - 1 & ")"
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Multiple Dynamic Named Ranges across Columns

On Monday, July 30, 2012 6:17:45 PM UTC-5, Steve wrote:
Hi all. I have been using the following formula to create dynamic named ranges:

=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A),1)



Where A1 is the column header of the data to be included in the named range.



Now I need to create dynamic named ranges from Column A thru Column CK. Is there a way to do this with code so I don't have to manually create each one? The data in row 1 is what I would like the name of the range to be.



Thanks in advance!


That will not make each column dependent on the last cell in that column.
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
Dynamic Named Ranges - is this possible? Code Numpty Excel Worksheet Functions 2 March 10th 10 04:01 PM
Dynamic Named Ranges SJT Excel Discussion (Misc queries) 4 June 9th 06 11:13 PM
Dynamic Named Ranges [email protected] Charts and Charting in Excel 0 March 9th 06 03:09 PM
Dynamic Named Ranges clane Excel Discussion (Misc queries) 5 October 13th 05 03:26 PM
Dynamic Columns in Named Ranges Pontificateur Excel Programming 4 September 17th 05 02:14 AM


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