I want to create a variant in the Worksheet_Change event and then use it in a module / macro.
The below code creates the variant but it does not keep it for the next macro.
- Code: Select all
Public MyVar As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyVar As Variant
Application.EnableEvents = False
If Target.Columns.Count = 1 Then
MyVar = "EEEEE"
Call test1
End If
Application.EnableEvents = True
End Sub
and the module
- Code: Select all
Public MyVar As Variant
Sub test1()
Sheets("Sheet2").Range("A1") = MyVar
End Sub
Where I'm wrong?