+ Reply to Thread
Results 1 to 3 of 3

Msgbox based on If statement

  1. #1
    Neil Jimack
    Guest

    Msgbox based on If statement

    I have a macro assigned to a button, but it can only run if a particular cell
    is zero. If the cell is greater than or less than zero, I want a message box
    to appear telling the user that the cell in question isn't zero.

    I know the code for making the Msgbox appear, but don't know the syntax for
    only having the box appear if the cell in question isn't zero.

    Any advice?

  2. #2
    JE McGimpsey
    Guest

    Re: Msgbox based on If statement

    One way:

    Public Sub Test
    If Range("A1").Value <> 0 Then
    MsgBox "Cell A1 must be equal to zero"
    Else
    'your code here
    End If
    End Sub

    Or, slightly more robust


    Public Sub Test
    Dim bSuccess As Boolean
    With Range("A1")
    If IsNumeric(.Value) Then
    If .Value = 0 Then
    'your code here
    bSuccess = True
    End If
    End If
    End With
    If Not bSuccess Then _
    MsgBox "Cell A1 must be equal to zero"
    End Sub

    In article <5057536C-9C0F-4D55-ADBC-C7A0288F53C4@microsoft.com>,
    "Neil Jimack" <Neil Jimack@discussions.microsoft.com> wrote:

    > I have a macro assigned to a button, but it can only run if a particular cell
    > is zero. If the cell is greater than or less than zero, I want a message box
    > to appear telling the user that the cell in question isn't zero.
    >
    > I know the code for making the Msgbox appear, but don't know the syntax for
    > only having the box appear if the cell in question isn't zero.
    >
    > Any advice?


  3. #3
    Nick
    Guest

    RE: Msgbox based on If statement

    Try This ...

    If Range("A1").FormulaR1C1 <> 0 Then
    'run your code here
    ActiveWindow.SelectedSheets.PrintPreview
    Else
    MsgBox ("Cell [A1] cannot equal Zero")
    End If

    regards, Nick

    "Neil Jimack" wrote:

    > I have a macro assigned to a button, but it can only run if a particular cell
    > is zero. If the cell is greater than or less than zero, I want a message box
    > to appear telling the user that the cell in question isn't zero.
    >
    > I know the code for making the Msgbox appear, but don't know the syntax for
    > only having the box appear if the cell in question isn't zero.
    >
    > Any advice?


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1