ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   running a macro on another worksheet (https://www.excelbanter.com/excel-programming/380013-running-macro-another-worksheet.html)

BRC

running a macro on another worksheet
 
I have a workbook with several sheets. when i enter values into
certain cells on WS1 i want each sheet to run a macro to analyze those
values. For instance; in WS2 I have a macro that fills in a table on
ws2. In WS3 there is a macro that fills in a table on WS3 etc. I am not
sure if I should be trying to run the macros on their specific sheets
or put them in a module and somehow code the output to the respective
sheets. I have a command button on sheet to start the process. Any
suggestions would be appreciated. thanks, BRC


Martin Fishlock

running a macro on another worksheet
 
It depends on your style how you structure your code and where the code is
used.

But you need to initiate the code either with a butoon or using one of the
change events (assuming check cell A1 on sheet1). This code goes into the
code for the worksheet:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Me.Range("A1"), Target) Is Nothing) Then
'call your rountines
CELL1
End If
End Sub

' this can go into the code for the sheet1 or a new module
Private Sub CELL1()
Worksheets("Sheet2").Range("A1") = Time
End Sub

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"BRC" wrote:

I have a workbook with several sheets. when i enter values into
certain cells on WS1 i want each sheet to run a macro to analyze those
values. For instance; in WS2 I have a macro that fills in a table on
ws2. In WS3 there is a macro that fills in a table on WS3 etc. I am not
sure if I should be trying to run the macros on their specific sheets
or put them in a module and somehow code the output to the respective
sheets. I have a command button on sheet to start the process. Any
suggestions would be appreciated. thanks, BRC



Otto Moehrbach

running a macro on another worksheet
 
BRC
I would use a Worksheet_Change macro in WS1. The code in that macro
would determine if the change that occurred was in any of the "certain"
cells. If that is the case, that macro would then call a regular (not
event) macro that itself calls each of the other macros. Each of the other
macros would contain code to direct the actions to the desired sheet.
Please post back if you need more. HTH Otto
"BRC" wrote in message
ups.com...
I have a workbook with several sheets. when i enter values into
certain cells on WS1 i want each sheet to run a macro to analyze those
values. For instance; in WS2 I have a macro that fills in a table on
ws2. In WS3 there is a macro that fills in a table on WS3 etc. I am not
sure if I should be trying to run the macros on their specific sheets
or put them in a module and somehow code the output to the respective
sheets. I have a command button on sheet to start the process. Any
suggestions would be appreciated. thanks, BRC





All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com