0
我想知道在计算行时是否可以使用if else语句。所以我将数据从一个工作簿导入到另一个工作簿。如果U列中的单元格为空,它将不会导入它,而是转到下一个单元格。
但是,导入行的总数仍在计算跳过的行数,因为它从选定区域开始计数。
那么是否有可能排除列U中可能有空单元格的那些?使用if语句来计算行
复活节快乐
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
“valg.Cells”和“wkbCurrent.ActiveSheet.Range(”U“:U”)“中的行之间的关系有点难以理解,但Application.CountA(wkbCurrent.ActiveSheet.Range (“U”:U“))'或'Application.CountIf(wkbCurrent.ActiveSheet.Range(”U“:U”),“<>”)'返回U:U中非空白单元格的计数那实际上是被复制过来的? – Jeeped 2015-04-03 12:51:36