Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

error in IF statement with cell reference


  • Please log in to reply

#1
rmccafferty

rmccafferty

    Member

  • Member
  • PipPip
  • 16 posts
I tried to insert the following code into an Excel macro

If Range("m1") = "" Then
MsgBox ("Number of Units is blank")
End If

I am doing something wrong, because I get the msgbox whether cell m1 is empty or not. Can anyone help me with the correct syntax?
  • 0

Advertisements


#2
Vino Rosso

Vino Rosso

    Visiting Staff

  • Visiting Consultant
  • 235 posts
Works for me.

Sub Test()

If Range("m1") = "" Then
MsgBox ("Number of Units is blank")
Else: MsgBox ("The cell is not blank.")
End If
End Sub


  • 0

#3
Jonesey

Jonesey

    Member

  • Member
  • PipPipPip
  • 335 posts

I tried to insert the following code into an Excel macro

If Range("m1") = "" Then
MsgBox ("Number of Units is blank")
End If

I am doing something wrong, because I get the msgbox whether cell m1 is empty or not. Can anyone help me with the correct syntax?


Your syntax is correct and works for me.

You could try this:

If Range("m1") = "" Then MsgBox ("Number of Units is blank") (syntax 1)

That way you don't need the end if statement.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP