IF A1 has content - run macroA Else do nothing …?

为君一笑 提交于 2020-01-16 18:35:28

问题


I have a button signed to a Macro, However if cell A1 has no content I get the debug error (runs via that)

I was wondering, as title says.. Can I run a IF command with a Macro?

So, If Sheet1!A1 = ANY content (differs from time to time) THEN run macroA

IF Sheet1!A1 = no content THEN do nothing (button just does nothing)

Possible?


回答1:


Please try:

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  

Not quite do nothing - displays a warning of why nothing (much) happened. But comment out the MsgBox line if you prefer.



来源:https://stackoverflow.com/questions/21808088/if-a1-has-content-run-macroa-else-do-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!