Can't call a Sub

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
241
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi all,

I want to run a Subroutine when a user of my workbook leaves a sheet. I have written the code in the ThisWorkbook section of the book. It is called "Update Table".

I entered this in the Worksheet code section:

VBA Code:
Private Sub Worksheet_Deactivate()
 
Call UpdateTable

End Sub

But it tells me the Sub is not defined.

Can I only run self-contained code in the Worksheet code section? Because there are 70 sheets that I want to do this with, and that's a lot of code to maintain when we make changes!
 
Last edited by a moderator:
Yes, but you'd probably want Select Case Sh.Name, or perhaps use codename.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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