worksheet_change help
In the Project Explorer window, right click the worksheet you want to use as
the trigger for calling the macro, and click view code. There are two white
boxes at the top of the code window, one says (General) and the other
(Declarations)
Change General to "Worksheet", change Declarations to "Change", and in the
sub it generates for you, use the following code:
Application.enableevents = false
Call R4R5Rest
Application.enableevents=true
Sam
"Mike B." wrote:
I have a macro that I want to apply to a specific worksheet. So that when I
go to the worksheet and change any cell, the sheet will automatically call
the macro.
I have R4R5Reset already in a module and know I have to go to the specific
sheet to do some private sub worksheet_????. I just don't know how to get to
call it everytime I change any cell on the sheet.
Option Explicit
Sub R4R5Reset()
'Define Variables
Dim InPutOne, InPutTwo, InPutThree As Double
Dim OutPutOne, OutPutTwo As Range
Dim Input3 As Range
Dim first As Boolean
Dim last As Boolean
'Set Variables
InPutOne = Range("AA12").Value
InPutTwo = Range("C11").Value
Set OutPutOne = Range("Y6")
Set OutPutTwo = Range("X23")
Set Input3 = Range("S16")
'Booleans
first = OutPutOne.Value = "UNLATCH"
last = OutPutTwo.Value = "LATCH"
'Different scenarios
If InPutOne = 0 And InPutTwo = 0 And first Then
InPutThree = 0
ElseIf InPutOne = 0 And InPutTwo = 1 Then
InPutThree = 1
ElseIf InPutOne = 1 And InPutTwo = 1 Then
InPutThree = 1
ElseIf InPutOne = 0 And InPutTwo = 0 And first = False Then
InPutThree = 1
first = True
ElseIf InPutOne = 1 And InPutTwo = 0 Then
InPutThree = 0
End If
'Results
If InPutThree = 0 Then
OutPutOne.Value = "UNLATCH"
OutPutTwo.Value = ""
Input3.Value = 0
ElseIf InPutThree = 1 Then
OutPutTwo.Value = "LATCH"
OutPutOne.Value = ""
Input3.Value = 1
End If
End Sub
|