Try this code
Option Explicit
Sub create_format()
Dim i As Long, lrow As Long, lcol As Long, lcol1 As Long
With Worksheets("Sheet1")
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = lrow To 2 Step -1
If .Range("A" & i).Value = .Range("A" & i - 1).Value Then
lcol = .Range("IV" & i - 1).End(xlToLeft).Column
lcol1 = .Range("IV" & i).End(xlToLeft).Column
.Range(.Cells(i, 4), .Cells(i, lcol1)).Copy .Cells(i - 1, lcol + 1)
.Rows(i).Delete
End If
Next i
For i = 6 To .UsedRange.Columns.Count Step 2
If Application.WorksheetFunction.CountA(.Columns(i)) >= 1 Then
.Cells(1, i).Value = "User Id"
.Cells(1, i + 1).Value = "Username"
End If
Next i
.Rows(1).Font.Bold = True
End With
End Sub
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose Tools | Macro | Macros
Select a macro in the list, and click the Run button
Bookmarks