drom
Well-known Member
- Joined
- Mar 20, 2005
- Messages
- 528
- Office Version
- 2021
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
Hi and thanks in advance!
If I wanna check if a sheet containg combined cells I can use:
But If I have X different merged Ranges, eg:
How can I get every mergedRange address kind of:
RED
If I use the macro recorder in a sheet with merged cells, I can activate them as follows
But I do not want to activate any range
I would like to get the different mergedarea's address
This is why I would like to know how can I get something like the prior RED wrong macro
If I wanna check if a sheet containg combined cells I can use:
VBA Code:
Sub Macro1()
Dim rRange As Range
Dim rMergedCells As Range: Set rMergedCells = ActiveSheet.Cells.Find( _
What:="", After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=True)
If rMergedCells Is Nothing Then Exit Sub
MsgBox "YES, we have merged cells eg:" & Chr(10) & Chr(10) & rMergedCells.MergeArea.Address
End Sub
But If I have X different merged Ranges, eg:
- B5:C10
- D9:G15
- X2:X4
- AB2:AC40
How can I get every mergedRange address kind of:
RED
VBA Code:
For Each rRange In ActiveSheet.MergeAreas
Debug.Print rRange.MergeArea.Address
Next
If I use the macro recorder in a sheet with merged cells, I can activate them as follows
VBA Code:
Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=True).Activate
Cells.FindNext(After:=ActiveCell).Activate
Cells.FindNext(After:=ActiveCell).Activate
Cells.FindNext(After:=ActiveCell).Activate
But I do not want to activate any range
I would like to get the different mergedarea's address
This is why I would like to know how can I get something like the prior RED wrong macro