Select row apart from a merged area
A while ago, one of our highly thought of members wrote this section of code in reply to a request to select a row other than a merged area. The code works, ( mind you that was never ever doubted, as Bob hardly ever produced code that didn't work.)
Code:
Function NotMerged(testRange As Range) As Range
Dim rngMA As Range
Dim cell As Range
Dim rngExclude As Range
For Each cell In testRange
Set rngMA = cell.MergeArea
If rngMA.Address <> cell.Address Then
If rngExclude Is Nothing Then
Set rngExclude = cell
Else
Set rngExclude = Union(rngExclude, cell)
End If
End If
Next cell
If rngExclude Is Nothing Then
Set NotMerged = testRange
Else
Set rngMA = rngExclude.Cells(1, 1).MergeArea
rngMA.MergeCells = False
Set NotMerged = AntiUnion(testRange, rngExclude)
rngMA.MergeCells = True
End If
End Function
Function AntiUnion(SetRange As Range, UsedRange As Range) As Range
Dim saveSet
saveSet = SetRange
SetRange.ClearContents
UsedRange = 0
Set AntiUnion = SetRange.SpecialCells(xlCellTypeBlanks)
SetRange = saveSet
End Function
Experience tells us to stay away from "Merged cells" as they are a problem when using VBA. Can someone kindly break this down for me to follow? Particularly the lines
Code:
If rngExclude is nothing Then
Set rngExclude = cell
Isn't "cell" one of those meant to be not used words within Excel?