[英]Excel-VBA : Skip subroutine if cell is empty
好的,所以我有10列,標記為“ A”-“ J”。
每行將有這些列的某種組合,並用字符串值填充。
我需要運行一些條件語句,我想知道是否有一種更有效的方法來執行它們,而不必簡單地遍歷所有語句。
我現在所擁有的:
If isempty("A1) then
Else
if isempty("B1") then
else
Sheet2!"B1" = "A1 and B1"
end if
if isempty("C1") then
else
Sheet2!"A1" = "A1 and C1"
end if
[...etc]
end if
If isempty("B1) then
Else
if isempty("C1") then
else
Sheet2!"B1" = "B1 and C1"
end if
if isempty("D1") then
else
Sheet2!"C1" = "C1 and D1"
end if
[...etc]
end if
它很長,很麻煩,而且不是很漂亮。 此外,這需要很長時間,因為我們要經歷幾百條記錄(行)。 有沒有一種更快的方法來查看X Row,比如說A,B,C,E和J擁有東西,並根據該東西做事。
If A,C,&J are filled Do this..
If B is empty do this...
If C Or D is full, do this other thing.
我不能完全確定應檢查單元格的順序,但這也許可以幫助您入門。
Dim rw As Long, lr As Long
With Cells(1, 1).CurrentRegion
lr = .Rows.Count
For rw = 1 To lr
If Application.CountA(Range("A" & rw & ",C" & rw & ",J" & rw)) = 3 Then
'If A,C,&J are filled Do this..
ElseIf IsEmpty(Range("B" & rw)) Then
'If B is empty do this...
ElseIf CBool(Application.CountA(Range("C" & rw & ",D" & rw))) Then
'If C Or D is full, do this other thing.
End If
Next rw
End With
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.