How to sheet index in calculate event

DeepButi

New Member
Joined
Jul 14, 2015
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a common Sub called for several sheets when calculate event fires, so the code inserted is:
Code:
Private Sub Worksheet_Calculate()                   ' On Sheet number 2
    Call Drawing(2)
End Sub
Private Sub Worksheet_Calculate()                   ' On Sheet number 5
    Call Drawing(5)
End Sub
Private Sub Worksheet_Calculate()                   ' On Sheet number 6
    Call Drawing(6)
End Sub

Sub Drawing(Sh As integer)                              ' On a Module
.... mycode here
....  Worksheets(sh).              used as Sheet to get info and perform operations
End Sub

I cannot use Call Drawing(Activesheet) because Activesheet is the sheet firing all 3 events at once, not the sheet actually performing mycode.

Any idea how to get the adequate index?

Thks
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try passing the worksheet object to your common code & see if that helps you

sheet code

VBA Code:
Private Sub Worksheet_Calculate()                   ' Event On Sheet code page
    Call Drawing(Me)
End Sub

Module Common code

VBA Code:
Sub Drawing(ByVal sh As Object)                              ' On a Module

     MsgBox sh.Name

'.... mycode here

End Sub

Dave
 
Upvote 0
Solution
Thanks, it works. Sometimes you don't see the most obvious method!
 
Upvote 0
Thanks, it works. Sometimes you don't see the most obvious method!

no worry we are all probably guilty doing the same - glad resolves your issue & appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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