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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
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
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,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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
Back
Top