I have a VBA script, that goes as follows:
1, it will run when particular sheet is selected
2, it will check if condition is True
3, if so, show MsgBox
Private Sub Worksheet_Activate()
Dim current As Double
current = Round(((Range("AJ9").Value / Range("AG9").Value) * 100), 1)
If Range("AJ9").Value / Range("AG9").Value < 0.15 Then
MsgBox "Here is some message and some value: "& current & "%."
End If
End Sub
I want to show this MsgBox only first time, when user come to the sheet. Now it pops up every time user get to the sheet. I have tried to use variable from different Sub, but it seems like it doesn't work.
Public read As Boolean
Sub readValue(Optional readArg As Boolean)
MsgBox readArg
read = (readArg Or False)
End Sub
and then I modified first Sub like this:
Private Sub Worksheet_Activate()
Dim current As Double
current = Round(((Range("AJ9").Value / Range("AG9").Value) * 100), 1)
Call readValue
If read = False Then
If Range("AJ9").Value / Range("AG9").Value < 0.15 Then
MsgBox "Here is some message and some value: "& current & "%."
readValue read = True
End If
End If
But the MsgBox readArg always says False. It's like it isn't sending value at all. Therefore MsgBox shows everytime user come to the sheet.
What am I doing wrong?