Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running msgbox's from an event procedure

Status
Not open for further replies.

johnkiddier

Technical User
Dec 14, 2001
2
GB
Sorry to bother everyone here, but I'm starting to learn VBA and having some difficulty running the following routine in Excel:

Private Sub Worksheet_Calculate()
If Range(&quot;a25&quot;).Value <>0 Then
MsgBox (&quot;Imbalance&quot;)
End If


End Sub

I'm placing the macro in the Worksheet Class Module but it won't run on calculation of the sheet.

If I follow the book I'm reading and insert the following code it does run.

Private Sub Worksheet_Calculate()
Columns(&quot;A:F&quot;).AutoFit
End Sub

Any ideas anyone?

I'm no doubt doing something really stupid but any help is much appreciated.

Many thanks

John Kiddier
 
This will in the Calculate event, but I don't think it will give you the results you are looking for. I highly recommend you use something like this as a cell formula:
Code:
=if(a25<>0,&quot;IMBALANCE&quot;,&quot;&quot;)
--------------
A little knowledge is a dangerous thing.
 
Thanks for replying.

I'm using Excel as a front end for an OLAP database and the line with the reconciliation on is hidden from users. I only need to know about if it doesn't balance. An event procedure would be the sort of thing that would be very helpful.

As I'm working through my VBA manual I also want to try and apply it to the various models I use.

Cheers.

John K.
 
OK
Your code looks fine. The only thing I can think of that would cause it not to execute is that there are no calculations being done. That is, the Calculate event isn't firing - as would be the case if there were no formulas in the sheet. --------------
A little knowledge is a dangerous thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top