Merging identical cells

Solved
ReM -  
maxclo69150 Posted messages 1 Status Member -
Hello

I've sorted some data and I have repeating rows (3 times the same value, then 2 times another, etc.). I would like to automatically merge the cells for better readability, but I'm stuck...

Thank you

12 answers

gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 744
 
Hello

If you want a macro that merges all vertical duplicates with range parameters and without confirmation messages, you can try this:
Sub merge_vertical_duplicates() Dim l As Long ' row Dim d As Long ' duplicates Dim c As Integer ' column Const minl = 1 ' start row Const maxl = 6 ' end row Const minc = 1 ' start column Const maxc = 2 ' end column Application.ScreenUpdating = False Application.DisplayAlerts = False For c = minc To maxc For l = minl To maxl For d = l + 1 To maxl If (Cells(l, c) <> Cells(d, c)) Then Exit For Next d If d > l + 1 Then With Cells(l, c).Resize(d - l, 1) .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With End If Next l Next c Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub 

--

Always zen
7
Allan
 
Hello gbinforme,

Your macro indeed works for the example I provided above, but what I'm looking for is a macro that allows me to perform the same task without any line limit. In mine, the issue is that I always have to modify the macro based on the total number of lines in the table I'm working on.

I suppose that to avoid the error message, it was actually sufficient to enter the phrase: "Application.DisplayAlerts = True".
Thank you for this tip ;)

Allan
0
Hugues
 
Super script thank you!
0
maxclo69150 Posted messages 1 Status Member
 
Hello,

thank you for this script.

I am trying to adapt it for horizontal merging without success. Can you help me?
0