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