Checking Named Range for Overlapping Merges Cells

Eldrod

Board Regular
Joined
Mar 11, 2010
Messages
76
I'm looking to see if any one has any code snippets to flag a condition where a Named range contains cells that merge outside the range itself. For example, I could have a named range for B1:F1 which is 5 columns, but in this case, let's say cell F1 is merged with G1. So these count as one cell.
The issue is that I use excel as a development platform for an online engine and the above condition causes issues. That condition is usually accidentally created, but it takes a lot of head scratching to find it.
It would work great if I could tell that the actual range is 6 columns, but the range.columns.count is reporting 5 . That would be good enough for me to generate an error message.
Any help is greatly appreciated!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Re: Checking Named Range for Overlapping Merged Cells

Thanks for anyone who noodled on this problem for me, but I figured out a resolution. Here's the code to do this:
Code:
Function Validate_Named_Range_Space(NR_Reference As String) As Integer
Dim Count_Select As Integer
Dim Count_NR As Integer
Dim Column_Mismatch As Boolean
Dim Row_Mismatch As Boolean

Validate_Named_Range_Space = 0
'Check the colunms to see if there are merged cells outside the named range
Range(NR_Reference).Select
Count_Select = Selection.Columns.Count
Count_NR = Range(NR_Reference).Columns.Count

If Count_Select <> Count_NR Then
    Column_Mismatch = True
Else
    Column_Mismatch = False
End If

'Check the rows to see if there are merged cells outside the named range
Range(NR_Reference).Select
Count_Select = Selection.Rows.Count
Count_NR = Range(NR_Reference).Rows.Count

If Count_Select <> Count_NR Then
    Row_Mismatch = True
Else
    Row_Mismatch = False
End If

Validate_Named_Range_Space = 0
If Column_Mismatch Then Validate_Named_Range_Space = 1
If Row_Mismatch Then Validate_Named_Range_Space = 2
If Column_Mismatch And Row_Mismatch Then Validate_Named_Range_Space = 3
  
End Function
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

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