Auto Range Name

John117

Active Member
Joined
Sep 29, 2004
Messages
371
Hello
Col B has series of merged cells. I would like assign macro to a button to automatically create name range to these merged cells if the merge cell has any text in it (if any name exists there go to next cell).
My recorded macro so far:

Code:
Sub Make_Name()
    Range("B11:B13").Select
    ActiveWorkbook.Names.Add Name:="func1", RefersToR1C1:="=Notes!R11C2"
    ActiveWorkbook.Names.Add Name:="func2", RefersToR1C1:="=Notes!R14C2"
    ActiveWorkbook.Names.Add Name:="func3", RefersToR1C1:="=Notes!R19C2"
    Range("A11").Select
End Sub

I would like search entire Col B starting at B11for merged cells with text. In addition the # of rows in merged cells will very. Range name will be sequential Func1, Func2 , etc……
Can you please help me with this code.

Thank you
John
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi -
How about;
Code:
sub test()
Dim i As Long
n = 1
For i = 11 To Range("b" & Rows.Count).End(xlUp).Row
    If Cells(i, "b").Value > 0 And Cells(i, "b").MergeCells = True Then
        ActiveWorkbook.Names.Add Name:="func" & n, RefersTo:=Sheets("Notes").Cells(i, "b").Value
            n = n + 1
    End If
Next
End Sub
 
Upvote 0
Thank you agihcam

Your code works very well with very small modification:

Rich (BB code):
Sub Range_Names()
Dim i As Long
n = 1
For i = 11 To Range("b" & Rows.Count).End(xlUp).row
    If Cells(i, "b").value > 0 And Cells(i, "b").MergeCells = True Then
        ActiveWorkbook.Names.Add Name:="func" & n, RefersTo:=Sheets("Notes").Cells(i, "b").value
        n = n + 1
    End If
Next
Range("A10").Select
End Sub
I had to remove the portion of the code highlighted in red.
Thank you very much.
John
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top