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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,433
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

jthomson

New Member
Joined
May 29, 2015
Messages
2
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,119
Messages
5,640,218
Members
417,131
Latest member
Seanr19871

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
Top