LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Named Range maker code

This code works okay. I found and modified the original to do a single named range by selecting the cell with the "Name_to-be" in it and run the code.

It produces a Refers To: offset formula to make the range dynamic like this, where the cell selected was H1 and with a name in H1.

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

All that is fine.

Howerer, if the selected cell and name is in cell H5, the code gives up the same offset formula instead of refering to H6 and on down.

I tried to incorporat the sRow value into the formula in place of "R2C" but failed at that. It would also need to change the COUNTA formula part to "Sheet1!$H6:$H???)-1,1)" or whatever.

At a loss to get that done.

Thanks,
Howard


Sub DynamicNameMaker()

Dim Col As Long
Dim sName As String
Dim Sht As String
Dim sRow As Long

'**Select the cell that will be the range name and header location

'grab sheet name
Sht = "'" & ActiveSheet.Name & "'"

With Selection

Col = ActiveCell.Column 'c.Column
sName = ActiveCell.Value
sRow = ActiveCell.Offset(1, 0).Row

If Len(sName) 1 Then
'replace spaces with underscores
sName = Replace(sName, " ", "_", 1)

MsgBox "The named range name will appear as" _
& vbCr & vbCr & " " & sName _
& vbCr & vbCr & "in the Name Manager."

'create the name
ActiveWorkbook.Names.Add Name:=sName, RefersToR1C1:= _
"=OFFSET(" & Sht & "!R2C" & Col & ",0,0,COUNTA(" & Sht & "!C" & Col & ")-1,1)"

End If

End With
End Sub
 
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
Code to change a named range Brian Excel Programming 3 April 13th 10 02:55 PM
Named range in workseet code Dave Excel Programming 8 December 21st 09 11:29 PM
Code to Run PDF Maker DevDaniel Excel Programming 1 March 28th 07 01:15 AM
Problem getting the value of a Named Range in code tbone[_2_] Excel Programming 1 March 21st 06 02:20 AM
Named Range Fails in VBA Code Dean Hinson[_3_] Excel Programming 3 January 24th 05 03:48 PM


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