Hi Derek,
I know this is a long shot but this code has been really helpful to me it does exactly what I had been looking for and I've been trying to expand on it a bit to do a couple extra things and I keep running into weird little errors. This code and my extras work on one sheet but if I expand it to others it that's when I start having issues.
1. If I leave my If, Then, Else statement out and it will work across multiple sheets no problem but some sheets I work with wont have merged cells
2. if it is included it seems that my else statement doesnt happen or the code is now not seeing merged cells
3. If I F8 through the cells it repeats exactly where it should but for some reason doesnt see the merged cells
and now there is a dent in my wall the size of my head because I cant figure it out haha
here is the code any and all help is appreciated
Option Explicit
Sub FindMerged()
'Modified from Mr.Excel user Derek
'Finds or doesnt find merged cells, then unmerges
'Future after unmerge calls the macros then remerges
'Future otherwise it just calls the macros
Dim str As String
Dim stri As String
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range
Dim sh As Worksheet
Application.ScreenUpdating = False
'For Each sh In ActiveWorkbook.Worksheets
' sh.Activate
Set rng1 = Cells.Find("*", [A1], xlFormulas, , xlByRows, xlPrevious)
Set rng2 = Cells.Find("*", [G1], xlFormulas, , xlByColumns, xlPrevious)
If Not rng1 Is Nothing Then
Set rng3 = Range([F2], Cells(rng1.row, rng2.Column))
Application.Goto rng3
End If
For Each rng3 In Selection
If rng3.MergeCells = False Then
'rng3.Select
MsgBox "no merged"
'Exit Sub
Else
str = rng3.Address
stri = stri & "," & str
End If
Next
stri = "(" & Mid(stri, 2, 1000) & ")"
'Range(stri).Select
For Each sh In ActiveWorkbook.Worksheets
sh.Activate
With Range(stri)
.UnMerge
End With
'With Range(stri)
'.Merge
'End With
Next sh
End Sub