Hi I have the below VBA but I dont want it to merge blank cells and would like to define the range eg I:AB
Sub MergeSame()Application.DisplayAlerts = FalseSet Rng = ActiveSheet.UsedRangeFor r = 1 To Rng.Rows.Count rngini = 1 Count = 2 For c = 1 To Rng.Columns.Count If Cells(r, c) = Cells(r, c + 1) Then Set Rng1 = Cells(r, rngini).Resize(, Count) Count = Count + 1 Else With Rng1 .Select .Merge .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With rngini = c + 1 Count = 2 End If NextNextApplication.DisplayAlerts = TrueEnd Sub</pre>
Sub MergeSame()Application.DisplayAlerts = FalseSet Rng = ActiveSheet.UsedRangeFor r = 1 To Rng.Rows.Count rngini = 1 Count = 2 For c = 1 To Rng.Columns.Count If Cells(r, c) = Cells(r, c + 1) Then Set Rng1 = Cells(r, rngini).Resize(, Count) Count = Count + 1 Else With Rng1 .Select .Merge .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With rngini = c + 1 Count = 2 End If NextNextApplication.DisplayAlerts = TrueEnd Sub</pre>