try this VBA solution:
Option Explicit
Sub books()
Dim sh1 As Worksheet, sh2 As Worksheet
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
Dim lr1 As Long, lr2 As Long, i As Long
lr1 = sh1.Range("A" & Rows.Count).End(xlUp).Row
lr2 = sh2.Range("A" & Rows.Count).End(xlUp).Row
sh2.Range("A1:D" & lr2).ClearContents
With sh1
.Range("A1:D1").Copy sh2.Range("A1")
For i = 2 To lr1
lr2 = sh2.Range("A" & Rows.Count).End(xlUp).Row
If .Range("C" & i) <> "" Then
.Range("A" & i & ":D" & i).Copy sh2.Range("A" & lr2 + 1)
End If
Next i
End With
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