I'm trying to get a listing of all of the cells that are merged on a worksheet. I want them listed in Column D of 'Sheet1', but I can't get the code quite right. Here's what I have so far:
Let's assume the first merged cell on "MySheet" is A1:F1.
What it's doing now is writing "$A$1", then going to the next cell down and writing "$B$1", then down one more and writing "$C$1", and so on.
What I need it to do is write the range that is merged, such as "$A$1:$F$1". I can't figure out how to get it to do it that way. Any ideas?
Code:
Dim c As Range
ThisWorkbook.Sheets("Sheet1").Activate
ThisWorkbook.Sheets("Sheet1").Range("D1").Select
For Each c In ThisWorkbook.Sheets("MySheet").UsedRange
If c.MergeCells Then
ActiveCell.Value = c.Address
ActiveCell.Offset(1, 0).Select
End If
Next
Let's assume the first merged cell on "MySheet" is A1:F1.
What it's doing now is writing "$A$1", then going to the next cell down and writing "$B$1", then down one more and writing "$C$1", and so on.
What I need it to do is write the range that is merged, such as "$A$1:$F$1". I can't figure out how to get it to do it that way. Any ideas?