Copy non blank data from sheet1 to sheet2 with VBA

How to copy non blank data from sheet1 to sheet2 with VBA. Sometimes we may have incomplete data in our Excel worksheet. Now we would like to create a separate worksheet with only the complete data. With VBA we can copy the completed data from one worksheet to another quickly and easily. Watch the training video below:

You can view this video on YouTube also.

Here’s the complete VBA code to quickly copy the completed data:

Sub copyNonBlankData()
Dim erow As Long, lastrow As Long, i As Long
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Sheet1.Cells(i, 1) <> “” Then
Sheets(“Sheet1”).Range(Cells(i, 1), Cells(i, 2)).Copy
Sheets(“sheet2”).Activate
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Sheets(“sheet2”).Range(Cells(erow, 1), Cells(erow, 2))
Sheets(“sheet1”).Activate
End If
Next i
Application.CutCopyMode = False
End Sub
Further study: