Hi everyone, I have a dataset in which the top row gives me the days of the year and the cells below contain a formula giving me the name of a promo that covers a certain amount of days. The result is a dataset in which every row has a certain amount of contigous cells containing the same content. While Others remain blank. I want to merge and center the cells with the same content. I am using this code, which worked in the past for a slightly similar dataset, and it is not working now. Can anyone correct it?
Here it is the code:
sub merge_same_cells()
Application.DisplayAlerts=False
Dim rng As Range
MergeCells:
For Each rng In Selection
If rng.value=rng.Offset(1,0).value and rng.value<>"" then
Range(rng,rng.Offset(1,0)).merge
Range(rng.Offset(1,0)).HorizontalAlignment=xlcenter
Range(rng.Offset(1,0)).VerticalAlignment=xlcenter
GoTo MergeCells
End If
Next
End Sub
Here it is the code:
sub merge_same_cells()
Application.DisplayAlerts=False
Dim rng As Range
MergeCells:
For Each rng In Selection
If rng.value=rng.Offset(1,0).value and rng.value<>"" then
Range(rng,rng.Offset(1,0)).merge
Range(rng.Offset(1,0)).HorizontalAlignment=xlcenter
Range(rng.Offset(1,0)).VerticalAlignment=xlcenter
GoTo MergeCells
End If
Next
End Sub