Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Pass variables from Worksheet_Calculate sub to Module

I have a bit of code that is triggered by the Worksheet_Calculate
event. I want to use this code of several worksheets but would prefer
not to repeat it in each Worksheet_Calculate event object. I thought
that at minimum, I could set the ranges specific to a particular sheet
in the Worksheet_Calculate event then hop over to module, and run the
code specific to the ranges. The ranges don't seem to pass to the
module.

Here's my Worksheet code. Any ideas why the values won't pass?

Public intShowing As Integer
Public w As Worksheet
Public rSheet As Range
Public rShow As Range
Public rData As Range
Public rCrit As Range
________________________________________________

Private Sub Worksheet_Calculate()


rSheet = ActiveWorksheet
rShow = rSheet.Range("RecordsShowing")
rData = rSheet.Range("Process_Data")
rCrit = rSheet.Range("FiltersCriteria_data")

ShowFilter 'Pass the range variables and run the ShowFilter sub from a
module

End Sub

________________________
Sub ShowFilter()
Msgbox "rSheet = " & rSheet
...etc

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Pass variables from Worksheet_Calculate sub to Module

The code in each sheet only responds to events from that sheet. If you want
something more global then use ThisWorkbook events...

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
'Determine if sheet need macro run on it
End Sub
--
HTH...

Jim Thomlinson


"John Michl" wrote:

I have a bit of code that is triggered by the Worksheet_Calculate
event. I want to use this code of several worksheets but would prefer
not to repeat it in each Worksheet_Calculate event object. I thought
that at minimum, I could set the ranges specific to a particular sheet
in the Worksheet_Calculate event then hop over to module, and run the
code specific to the ranges. The ranges don't seem to pass to the
module.

Here's my Worksheet code. Any ideas why the values won't pass?

Public intShowing As Integer
Public w As Worksheet
Public rSheet As Range
Public rShow As Range
Public rData As Range
Public rCrit As Range
________________________________________________

Private Sub Worksheet_Calculate()


rSheet = ActiveWorksheet
rShow = rSheet.Range("RecordsShowing")
rData = rSheet.Range("Process_Data")
rCrit = rSheet.Range("FiltersCriteria_data")

ShowFilter 'Pass the range variables and run the ShowFilter sub from a
module

End Sub

________________________
Sub ShowFilter()
Msgbox "rSheet = " & rSheet
...etc

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Pass variables from Worksheet_Calculate sub to Module

Thanks, Jim. I'll give that a shot. Sounds like it would be a better
approach anyway.

- John


Jim Thomlinson wrote:
The code in each sheet only responds to events from that sheet. If you want
something more global then use ThisWorkbook events...

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
'Determine if sheet need macro run on it
End Sub
--
HTH...

Jim Thomlinson


"John Michl" wrote:

I have a bit of code that is triggered by the Worksheet_Calculate
event. I want to use this code of several worksheets but would prefer
not to repeat it in each Worksheet_Calculate event object. I thought
that at minimum, I could set the ranges specific to a particular sheet
in the Worksheet_Calculate event then hop over to module, and run the
code specific to the ranges. The ranges don't seem to pass to the
module.

Here's my Worksheet code. Any ideas why the values won't pass?

Public intShowing As Integer
Public w As Worksheet
Public rSheet As Range
Public rShow As Range
Public rData As Range
Public rCrit As Range
________________________________________________

Private Sub Worksheet_Calculate()


rSheet = ActiveWorksheet
rShow = rSheet.Range("RecordsShowing")
rData = rSheet.Range("Process_Data")
rCrit = rSheet.Range("FiltersCriteria_data")

ShowFilter 'Pass the range variables and run the ShowFilter sub from a
module

End Sub

________________________
Sub ShowFilter()
Msgbox "rSheet = " & rSheet
...etc

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass variables as arguments of a function Excel-craze Excel Worksheet Functions 1 August 12th 09 11:48 AM
Pass variables value to Shell wpw3 Excel Programming 0 March 7th 05 03:55 PM
How to pass values from a userform to a standard module? TBA[_2_] Excel Programming 3 January 7th 04 01:50 PM
can variables pass values Don[_11_] Excel Programming 3 November 1st 03 04:50 PM
Pass a variable from a class module pk Excel Programming 1 October 2nd 03 08:24 PM


All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"