-2

I am trying to create a Macro. But am not entirely show how to get it to work.

I want the Macro to run if cell A1 is not blank. If cell A1 is blank I want a msgbox to appear informing the user to fill in cell A1 before the Macro will work.

IE in formula terms =if(A1<>"",do resest of macro,"Populate cell A1")

If someone could please help me create the condition do x or y depending on A1's value I would be most appreciative.

I think it should work something like below

Sub Code ()
If IsEmpty(Range("A1").Value) = True Then

Goto String1
Else 
Goto String2

String1:
MsgBox "Cell A1 is empty"
String2:
Rest of code
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
PGD15
  • 183
  • 2
  • 15
  • Possible duplicate of [Excel: How to check if a cell is empty with VBA?](https://stackoverflow.com/q/13360651/11683) – GSerg Aug 26 '19 at 08:48
  • @GSerg I want to the macro to continue by either running string 1 or string 2 if cell is empty or populated; respectively. . – PGD15 Aug 26 '19 at 08:51
  • 1
    So your question is how to put code inside an `If` block, rather than how to check if a cell is empty. – GSerg Aug 26 '19 at 08:54
  • @GSerg yes essentially, sorry if this was not clear, i've updated the question to include some VBA which i hope gives a better illustration – PGD15 Aug 26 '19 at 08:58
  • https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-else-statement#multiline-syntax-example – Marcucciboy2 Aug 26 '19 at 12:38

1 Answers1

0

I just called two macros

Sub ()

If IsEmpty(Range("A1").Value) = True Then
Call Macro1
Else
Call Macro2
End If
End Sub
PGD15
  • 183
  • 2
  • 15