Can anyone help me write a vba code to merge same value cells in different columns as shown below.
I have tried using the code below but doesn't work;
Sub mergeWeeks()
Dim lc As Long, nc As Long, cr As Long, rng As Range
Application.DisplayAlerts = False
With Worksheets("sheet2")
For cr = 1 To 2
lc = Application.Match("zzz", .Rows(cr))
Set rng = .Cells(cr, 1)
Do While rng.Column < lc
nc = Application.Match(rng.Value & "z", .Rows(cr))
rng.Resize(1, nc - rng.Column + 1).Merge
Set rng = rng.Offset(0, 1)
Loop
Next cr
End With
Application.DisplayAlerts = True
End Sub
See Question&Answers more detail:os