Moonbeam111
Board Regular
- Joined
- Sep 24, 2018
- Messages
- 73
- Office Version
- 365
- 2010
Hi all. Thank you for your time. I have a new question. I'm trying to NOT call a macro when a value changes but ONLY for the first time the value changes. After that the macro should run normally. To make this clear, here is my code.
As you can see I'm trying to use a combination of static integers and and a boolean to do this. Ultimate goal being when range("A195") changes at all, it adds +1 to the static numeral counter and skips over switch5p3. After that I DO want it to call switch5p3 but do not want it to add 1 to the numeral . Not UNTIL the value of range("A195") changes again, at which point it once again will add +1 to the numeral and not call switch 5p3. etc....
VBA Code:
Sub macroSheet_Button390_Click()
Application.ScreenUpdating = True
Static oldval As Integer
Static numeral As Integer
Dim hasrun As Boolean
Range("D27") = Range("D27") - Range("A33").Value
If Range("A195") <> oldval Then
oldval = Range("A195").Value
numeral = numeral + 1
hasrun = True
End If
If numeral = Range("A195") And Range("G47").Value > Range("F47").Value and hasrun = true Then
GoTo D27
End If
If hasrun = False Then
Call Switch5p3
End If
D27:
If Range("D27").Value < 0 Then
Range("D27").Value = 0
End If
If Range("D27").Value = 0 Then
Range("D37:I37").ClearContents
ActiveWindow.ScrollRow = 129
End If
Rows("31:35").EntireRow.Hidden = True
hasrun = False
End Sub
As you can see I'm trying to use a combination of static integers and and a boolean to do this. Ultimate goal being when range("A195") changes at all, it adds +1 to the static numeral counter and skips over switch5p3. After that I DO want it to call switch5p3 but do not want it to add 1 to the numeral . Not UNTIL the value of range("A195") changes again, at which point it once again will add +1 to the numeral and not call switch 5p3. etc....