Currently having a worksheet "invoice" with cell range of A19:F41 that will be able to input data and will be copying from worksheet "invoice" to worksheet "report" using the below code. But in between the range A19:F41, may have chances where some rows have no data in between some rows with data. How can I copy via VBA only rows with data to worksheet "report"? Thanks.
Dim rng As Range
Dim i As Long
Dim a As Long
Dim rng_dest As Range
Application.ScreenUpdating = False
i = 1
Set rng_dest = Sheets("Report").Range("F:J")
' Find first empty row in columns F:J on sheet Report
Do Until WorksheetFunction.CountA(rng_dest.Rows(i)) = 0
i = i + 1
Loop
'Copy range A19:F41 on sheet Invoice to Variant array
Set rng = Sheets("Invoice").Range("A19:F41")
'Copy rows containing values to sheet Report
For a = 1 To rng.Rows.Count
If WorksheetFunction.CountA(rng.Rows(a)) <> 0 Then
rng_dest.Rows(i).Value = rng.Rows(a).Value
'Copy Date
Sheets("Report").Range("A" & i).Value = Sheets("Invoice").Range("F10").Value
'Copy Invoice Number
Sheets("Report").Range("B" & i).Value = Sheets("Invoice").Range("F11").Value
'Copy CRM Number
Sheets("Report").Range("C" & i).Value = Sheets("Invoice").Range("F12").Value
'Copy Account Manager
Sheets("Report").Range("D" & i).Value = Sheets("Invoice").Range("F13").Value
'Copy Company name
Sheets("Report").Range("E" & i).Value = Sheets("Invoice").Range("B9").Value
'Copy Comments
Sheets("Report").Range("K" & i).Value = Sheets("Invoice").Range("A44").Value
i = i + 1
End If
Next a
Application.ScreenUpdating = True
End Sub
Dim rng As Range
Dim i As Long
Dim a As Long
Dim rng_dest As Range
Application.ScreenUpdating = False
i = 1
Set rng_dest = Sheets("Report").Range("F:J")
' Find first empty row in columns F:J on sheet Report
Do Until WorksheetFunction.CountA(rng_dest.Rows(i)) = 0
i = i + 1
Loop
'Copy range A19:F41 on sheet Invoice to Variant array
Set rng = Sheets("Invoice").Range("A19:F41")
'Copy rows containing values to sheet Report
For a = 1 To rng.Rows.Count
If WorksheetFunction.CountA(rng.Rows(a)) <> 0 Then
rng_dest.Rows(i).Value = rng.Rows(a).Value
'Copy Date
Sheets("Report").Range("A" & i).Value = Sheets("Invoice").Range("F10").Value
'Copy Invoice Number
Sheets("Report").Range("B" & i).Value = Sheets("Invoice").Range("F11").Value
'Copy CRM Number
Sheets("Report").Range("C" & i).Value = Sheets("Invoice").Range("F12").Value
'Copy Account Manager
Sheets("Report").Range("D" & i).Value = Sheets("Invoice").Range("F13").Value
'Copy Company name
Sheets("Report").Range("E" & i).Value = Sheets("Invoice").Range("B9").Value
'Copy Comments
Sheets("Report").Range("K" & i).Value = Sheets("Invoice").Range("A44").Value
i = i + 1
End If
Next a
Application.ScreenUpdating = True
End Sub