2016-06-23 47 views
0

我想如果我的细胞(b5,c5)比细胞(f5,g5,h5)空白也是空白的,细胞(b6,c6)比细胞(f6,g6, h6),细胞(b7,c7)比细胞(f7,g7,h7)空白,细胞(b8,c8)比细胞(f8,g8,h8)空白,细胞(b9,c9) F9,G9,H9),但同样我想这个代码200时间帮我做一个小code.thanks提前。Excel VBA如果那么陈述

Sub BLANK() 

    If Range("B5,C5") = "" Then 
    Range("F5,G5,H5") = "" 
    If Range("B6,C6") = "" Then 
    Range("F6,G6,H6") = "" 
    If Range("B7,C7") = "" Then 
    Range("F7,G7,H7") = "" 
    ' same code in cell("b5:b200") make small code please 
    end if 
    end sub 

回答

1

下面将循环200次以上,并生产出您需要

For x = 5 to 200 
    If Range(Cells(x,2), Cells(x,3)).Value = "" Then 
     Range(Cells(x,6), Cells(x,8)).Value = "" 
    End if 
Next x 
+0

SORRY那不行某些错误 –

1

的结果,我会建议更换你使用这样的事情。凡范围和纸张正确声明,以及所有变量都正确使用option explicit,以防止您从多个问题

Sub makeBlank() 

Dim mySheet As Worksheet 
Set mySheet = Sheets("devSheet") 

Dim rowCounter As Long 

With mySheet 
    For rowCounter = 5 To 200 
     If .Range("B" & rowCounter & ",C" & rowCounter).Value = "" Then 
      .Range("F" & rowCounter & ",G" & rowCounter & ",H" & rowCounter).Value = "" 
     End If 
    Next rowCounter 
End With 

End Sub 
+0

宣布谢谢你,这是在栈工作得非常好感谢 –

+0

@RameshVerma溢出感谢工作解决方案是通过接受答案或/和投票答案添加... –