How can I tell if VBA is running in an .XLSM?

Plasmech

New Member
Joined
Oct 26, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
I have a .xlsm with embedded VBA code. I believe the VBA code has stopped running.

How can I tell, definitively, if VBA is running?

Also, I would like to add something to the VBA code to show an error on the spreadsheet if VBA fails to run. What would the easiest way to go about this be? I'm thinking of a line of code that hides a "VBA FAULT" cell.

Thanks for any help, as always.

Please let me know if I'm not using the proper terminology.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How can I tell, definitively, if VBA is running?
When VBA is done "Ready" appears at the lower Left end of the status bar
Screenshot 2023-10-18 at 17.46.08.png
 
Upvote 0
Also, I would like to add something to the VBA code to show an error on the spreadsheet if VBA fails to run. What would the easiest way to go about this be? I'm thinking of a line of code that hides a "VBA FAULT" cell.
Generally if the VBA fails to run it shows up error...
 
Upvote 0
Note that one simple step you can do is to add message boxes at various points in your code.
For example, you can put this at the very top:
VBA Code:
MsgBox "VBA code has started to run"
and maybe something like this at the end of the code:
VBA Code:
MsgBox "VBA code complete"
So, if the code is running, you will get those Message boxes to pop up.

Are you, perchance, working with Event procedures?
If you are, perhaps you have accidentally disabled them, which means they will not run/fire anymore in your session of Excel. This often happens when you have VBA code that temporarily turns off events to make some updates, and turns it on again at the end, but you get some sort of error or other abend where the code at the end to turn it back on never runs.
You can turn them on again by manually running this procedure:
VBA Code:
Sub ReEnableEvents()
    Application.EnableEvents = True
End Sub
 
Upvote 0
Note that one simple step you can do is to add message boxes at various points in your code.
For example, you can put this at the very top:
VBA Code:
MsgBox "VBA code has started to run"
and maybe something like this at the end of the code:
VBA Code:
MsgBox "VBA code complete"
So, if the code is running, you will get those Message boxes to pop up.

Are you, perchance, working with Event procedures?
If you are, perhaps you have accidentally disabled them, which means they will not run/fire anymore in your session of Excel. This often happens when you have VBA code that temporarily turns off events to make some updates, and turns it on again at the end, but you get some sort of error or other abend where the code at the end to turn it back on never runs.
You can turn them on again by manually running this procedure:
VBA Code:
Sub ReEnableEvents()
    Application.EnableEvents = True
End Sub
Hi Joe,

Does VBA code run as one-and-done, or does it constantly loop? When would the "end" occur?

Thanks.

Also, AFIK, I am not using Event Procedures.
 
Upvote 0
Hi Joe,

Does VBA code run as one-and-done, or does it constantly loop? When would the "end" occur?

Thanks.

Also, AFIK, I am not using Event Procedures.
I cannot evaluate your code if you do not post it.
 
Upvote 0
I cannot evaluate your code if you do not post it.
Sorry, here you go:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C4")) Is Nothing And Not IsEmpty(Range("C4").Value) Then
If Range("C4").Value <> Sheets("lookup data").Range("E6").Value Then
Application.EnableEvents = False
'
With Range("C9")
If Range("C4").Value = "Metric" Then
.Value = .Value * 0.45359237
Else
.Value = .Value * 2.20462262
End If
End With
'
With Range("C12")
If Range("C4").Value = "Metric" Then
.Value = .Value * 16.0185
Else
.Value = .Value / 16.0185
End If
End With
'
Sheets("lookup data").Range("E6").Value = Range("C4").Value
Application.EnableEvents = True
End If
End If
 
Upvote 0
"Worksheet_Change" is 100% definitely an Event Procedure!!!
An "Event Procedure" VBA code is one that runs automatically upon some event happening, like the updating of a cell.

So you could have accidentally disabled events.
Try copying that little "ReEnableEvents" procedure I wrote for you and then run it manually, and see if that fixes your issue.

And you can temporarily add the following line to your code, just to ensure that the code is running:
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Code is being called"
If Not Intersect(Target, Range("C4")) Is Nothing And Not IsEmpty(Range("C4").Value) Then
If Range("C4").Value <> Sheets("lookup data").Range("E6").Value Then
Application.EnableEvents = False
'
With Range("C9")
If Range("C4").Value = "Metric" Then
.Value = .Value * 0.45359237
Else
.Value = .Value * 2.20462262
End If
End With
'
With Range("C12")
If Range("C4").Value = "Metric" Then
.Value = .Value * 16.0185
Else
.Value = .Value / 16.0185
End If
End With
'
Sheets("lookup data").Range("E6").Value = Range("C4").Value
Application.EnableEvents = True
End If
End If
Now, whenever you make a change anywhere on that sheet, you should get a message box pop-up saying "Code is being called".
If not, then you probably have this code in the wrong place.
 
Upvote 0
"Worksheet_Change" is 100% definitely an Event Procedure!!!
An "Event Procedure" VBA code is one that runs automatically upon some event happening, like the updating of a cell.

So you could have accidentally disabled events.
Try copying that little "ReEnableEvents" procedure I wrote for you and then run it manually, and see if that fixes your issue.

And you can temporarily add the following line to your code, just to ensure that the code is running:
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Code is being called"
If Not Intersect(Target, Range("C4")) Is Nothing And Not IsEmpty(Range("C4").Value) Then
If Range("C4").Value <> Sheets("lookup data").Range("E6").Value Then
Application.EnableEvents = False
'
With Range("C9")
If Range("C4").Value = "Metric" Then
.Value = .Value * 0.45359237
Else
.Value = .Value * 2.20462262
End If
End With
'
With Range("C12")
If Range("C4").Value = "Metric" Then
.Value = .Value * 16.0185
Else
.Value = .Value / 16.0185
End If
End With
'
Sheets("lookup data").Range("E6").Value = Range("C4").Value
Application.EnableEvents = True
End If
End If
Now, whenever you make a change anywhere on that sheet, you should get a message box pop-up saying "Code is being called".
If not, then you probably have this code in the wrong place.
I got VBA running. Not sure why it wasn't before. There was nothing wrong with the code. I even rebooted yesterday. Strange. I tried your

MsgBox "Code is being called"

It works. Thanks.

I would like to have VBA actively suppress a "VBA Fault" message (or cell contents). Is this possible?

Thanks again for all the help you have provided.
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

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