i have tried to write a code that sort and merge the cells with the same value and add headlines to each columns but it execute after 5min of loading and sometimes the program freezes until i restart it here it is my code .
ps: format macro calls merge_same_cells macro
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, rng.Offset(1, 0)).HorizontalAlignment = xlCenter
Range(rng, rng.Offset(1, 0)).VerticalAlignment = xlCenter
GoTo MergeCells
End If
Next
End Sub
Sub format()
Dim var As String
var = Application.InputBox(prompt:="nom du sheet")
If FeuilleExiste(var) = False Then
MsgBox "sheet doesn't exist"
Else
Range("B6") = "pannes"
Range("C6") = "pannes abrv"
Range("D6") = "nobmre"
Range("B6:D6").AutoFilter
ActiveWorkbook.Worksheets(var).AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets(var).AutoFilter.Sort.SortFields.Add Key:= _
Range("B6"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(var).AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("D:D").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Call Merge_Same_Cells
End If
End Sub