好的,我有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.
答案 0 :(得分:1)
我不完全确定应该检查单元格的顺序,但这可能会让你开始。
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