this should work for you
Option Explicit
Sub Normalize()
Dim s1 As Worksheet, s2 As Worksheet
Dim i As Long, lr As Long, lrt As Long
Dim lc As Long
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
lr = s1.Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = 1 To lr
lrt = s2.Range("B" & Rows.Count).End(xlUp).Row + 1
lc = s1.Cells(i, Columns.Count).End(xlToLeft).Column
s1.Range("A" & i).Copy s2.Range("A" & lrt)
s1.Range(Cells(i, 2), Cells(i, lc)).Copy
s2.Range("B" & lrt).PasteSpecial xlPasteValues, , , True
Application.CutCopyMode = False
Next i
lrt = s2.Range("B" & Rows.Count).End(xlUp).Row
For i = 3 To lrt
If s2.Range("A" & i) = "" Then
s2.Range("A" & i) = s2.Range("A" & i - 1)
End If
Next i
Application.ScreenUpdating = True
End Sub
How to install your new code
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
To run the Excel VBA code:- Press Alt-F8 to open the macro list
- Select a macro in the list
- Click the Run button
Bookmarks