Warning MsgBox for calculated cell?

Ronix

Board Regular
Joined
Aug 18, 2014
Messages
54
Hello Guys, I need to create warning message box which gonna be popped up everytime when result of "look up" calculation in cell D3 is "#N/A" or cell D3 is empty.
I have tried something like this, but it is not working for me:
Private Sub CommandButton1_Click()
If Range("D3").Calculate = "" Then
MsgBox "Running Test "
Else:
**other part of code**
end if
end sub

Then I´ve found here other code, first part worked well (box has been popped up) but if the result of calculation is OK the other part of code is not running:
Private Sub CommandButton1_Click()
If [IsError(d3)] Then
Select Case [d3]
Case CVErr(xlErrDiv0)
MsgBox "#DIV/0! error"
Case CVErr(xlErrNA)
MsgBox "Wrong data, correct it!"
Case CVErr(xlErrName)
MsgBox "#NAME? error"
Case CVErr(xlErrNull)
MsgBox "#NULL! error"
Case CVErr(xlErrNum)
MsgBox "#NUM! error"
Case CVErr(xlErrRef)
MsgBox "#REF! error"
Case CVErr(xlErrValue)
MsgBox "#VALUE! error"
Case Else
***other part of code***
end select
end if
end sub
Thanks in advance for your help!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Calculate()
If IsError(Range("D3")) Or Range("D3").Value = "" Then
    MsgBox "Warning", vbExclamation
End If
End Sub
 
Upvote 0

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Does something like this work
Code:
Private Sub CommandButton1_Click()
    On Error Resume Next
    If Range("D3").Value = "" Or IsError(Range("D3").Value) Then
        MsgBox "This is an error"
    Else
        Range("D3").Activate 'Other code goes here
    End If
End Sub
 
Upvote 0

Ronix

Board Regular
Joined
Aug 18, 2014
Messages
54
VoG in your code some error is in this line:

If IsError(Range("D3")) Or Range("D3").Value = "" Then

Momentman your code is working exactly I need

Thank you very much guys!
</pre>
 
Upvote 0

Forum statistics

Threads
1,195,991
Messages
6,012,731
Members
441,724
Latest member
Aalbid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top