Name of Merged Cells

jthomson

New Member
Joined
May 29, 2015
Messages
2
I am stumped! I have a good level of VB experience and have combed through VBA posts for answers but this one is beating me.

Here is where I am at:
- Merged 4 cells together (A1:B2)
- Renamed merged cells "SampleBlock"
- Select the range "SampleBlock" with the cursor so that it is the active cell

The code I need will recall the name (not address) of the merged cells when it is selected. I have this running no problem with single cell named ranges but when you are dealing with merged cells it blows up. VB will use the name "SampleBlock" for further operations. I can recall the address no problem ($A1:$B2) using the Address function but I need the actual name of the range not the "Refers To" address

I have tried:
x = Selection.Name.Name
x = Selection.MergeArea.Name
and a lot of other combinations...

Help if you can please!

Jeff
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If I merge A1:B2 and run this code, it produces the name I assigned to the merged range and the address of the upper left cell (A1) of that named, merged range.
Code:
Sub Test()
Dim nam As Name
For Each nam In Names
    MsgBox nam.Name & vbTab & nam.RefersTo
Next nam
End Sub
 
Upvote 0
That wasn't exactly what I was looking for as I think your method takes the name from the name register instead of from the selected cell. Building on what you started I was able to make it work:

Dim nam as Name
Set nam = ActiveCell.Name
x = Application.WorksheetFunction.Match(nam.Name, Range(Cells(1, 1), Cells(1, 1000)), 0)

Thanks! I needed to Dim it as a Name first. Glad I came for help on here!
-JT
 
Upvote 0

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

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