tjdickinson
Board Regular
- Joined
- Jun 26, 2021
- Messages
- 61
- Office Version
- 365
- Platform
- Windows
I am looking for code that will automatically unmerge empty, horizontally merged cells so that column lines will be visible, but which will not unmerge vertically merged cells (all of which contain data). The code will be inserted into a macro which will execute a number of other formatting processes, some of which depend on the cells being unmerged.
So far, the code I have is:
I had hoped that the text in the merged cells would prevent them from unmerging (thus the IsEmpty() function), but this code still unmerges all the cells. How can I fix the code so that only the empty horizontally merged cells unmerge? The main data range is B3:F15 on all sheets. A1:F1 are merged horizontally, but there is text in the merged cell.
So far, the code I have is:
VBA Code:
Sub UnMergeCell()
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If IsEmpty(cell.Value) = True Then
cell.Style = "Note" 'I'm using this in testing just to see which cells are affected
cell.UnMerge
End If
Next
End Sub
I had hoped that the text in the merged cells would prevent them from unmerging (thus the IsEmpty() function), but this code still unmerges all the cells. How can I fix the code so that only the empty horizontally merged cells unmerge? The main data range is B3:F15 on all sheets. A1:F1 are merged horizontally, but there is text in the merged cell.