问题
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