IF A1有内容 - 运行macroS Else什么都不做......?

时间:2014-02-16 06:29:21

标签: excel excel-vba vba

我有一个签名到宏的按钮,但是如果单元格A1没有内容我得到调试错误(通过它运行)

我想知道,正如标题所说..我可以用宏运行IF命令吗?

所以,如果Sheet1!A1 = ANY content(不时有所不同)THEN run macroA

IF Sheet1!A1 = no content THEN do nothing(按钮无效)

可能的?

1 个答案:

答案 0 :(得分:2)

请尝试:

Sub Macro1()
    If WorksheetFunction.CountA(Range("A1")) = 0 Then
        MsgBox "A1 is empty"
        Else
        Application.Run "Macro2()" 'edit macro name to suit
    End If
End Sub  

不完全do nothing - 显示为什么没有(很多)发生的警告。但如果您愿意,请注释掉MsgBox行。