• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy NonBlank Rows to another sheet

JSK_VBA

New Member
hi,
i have a data in sheet1 in col1 there are some titles and col2 has values.
in col 1 there are several cells are blank, i want to copy non blank data in sheet2.

pls suggest what code should i use??



Thanks in advance.
 
Code:
Option Explicit

Sub CpyNonBlank()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    Dim lr As Long, lr2 As Long
    Dim i As Long
    lr = s1.Range("B" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    With s1
        For i = 1 To lr
            lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
            If .Range("A" & i) <> "" Then
                .Range("A" & i & ":B" & i).Copy s2.Range("A" & lr2 + 1)
            End If
        Next i
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "Action complete"
End Sub
 
Back
Top