The code is not making a lot of sense. Every time the code runs the variable CurrentMarketID is set to be the value in Sheets("Gruss").Range("N3").Value, then you dump the value in Sheets("Race Card").Range("D1").Value and then you ask if the value of CurrentMarketID is different then Me.Cells(3, "N") which is the same that Sheets("Gruss").Range("N3").Value. So this can never work
try this
- Code: Select all
Public CurrentMarketID As Long
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
' First time the code runs Get current Market ID
If CurrentMarketID = 0 Then CurrentMarketID = Sheets("Gruss").Range("N3").Value
'Check if Market ID changes
If CurrentMarketID <> Sheets("Gruss").Range("N3").Value Then
CurrentMarketID = CurrentMarketID = Sheets("Gruss").Range("N3").Value
GetCard 'Run GetCard method
End If
Application.EnableEvents = True
End Sub