Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Neil Jimack
 
Posts: n/a
Default 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   Report Post  
JE McGimpsey
 
Posts: n/a
Default

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 ,
"Neil Jimack" <Neil 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   Report Post  
Nick
 
Posts: n/a
Default

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF Statement Brent New Users to Excel 3 April 29th 05 04:24 PM
Msgbox Wildman Excel Worksheet Functions 1 April 26th 05 04:57 AM
Can I select a worksheet based upon a cell criteria?(for printing) Tim Richards Excel Worksheet Functions 0 March 30th 05 07:03 PM
IF statement based on data type Reed Excel Worksheet Functions 1 January 20th 05 02:17 PM
Conditional formatting based on if statement. kevin Excel Worksheet Functions 2 January 12th 05 03:07 AM


All times are GMT +1. The time now is 05:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"