I was wondering if it is possible to use an if else statement when you are counting rows. So I am importing data from one workbook to another. If the cell in column U is empty, it will not import it but go to the next one.
However, the total count of imported rows is still counting the skipped one, since it is counting from the selected area.
So is it possible to exclude the ones that might have an empty cell in column U?
Happy Easter
For Each c In valg.Cells
If wkbCurrent.ActiveSheet.Range("U" & c.Row) <> "" Then
' Macro runs here
Else
MsgBox wkbCurrent.ActiveSheet.Range("H" & c.Row) & " must have an MDS ID" & vbNewLine & "Skipping this supplier and continue the import", vbCritical, "Error"
'Exit Sub
End If
Next
' Find the number of rows that is copied over
wkbCurrent.ActiveSheet.Activate
areaCount = Selection.Areas.Count
If areaCount <= 1 Then
MsgBox "The selection contains " & Selection.Rows.Count & " suppliers."
' Write it in A10 in CIF LISTEN
wkbNew.Worksheets(1).Range("A10").Value = "COMMENTS: " & Selection.Rows.Count & " Suppliers Added"
Else
i = 1
For Each A In Selection.Areas
'MsgBox "Area " & I & " of the selection contains " & _
a.Rows.count & " rows."
i = i + 1
rwCount = rwCount + A.Rows.Count
Next A
MsgBox "The selection contains " & rwCount & " suppliers."
' Write it in A10 in CIF LISTEN
wkbNew.Worksheets(1).Range("A10").Value = "COMMENTS: " & rwCount & " Suppliers Added"
End If
Aucun commentaire:
Enregistrer un commentaire