Excel-VBA:如果单元格为空,则跳过子程序

好吧,我有10列,标有“A” – “J”。

每行将有一些填充string值的列的组合。

我需要运行一些条件语句,我想知道是否有一个更有效的方法来做到这一点,而不是简单地遍历它们。

我现在拥有的:

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 

这是漫长的,繁琐的,不是很漂亮。 此外,由于我们有几百条logging(行)需要花费很长时间。 有没有更快的方式来看看X行,说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