Hi all,
I am trying to run a macro based on a cell value. I inserted the below code in the sheet where the cell exists. The code never runs and I added a msgbox just to double check and it doesnt fire up. Can you please help me out?
Many thanks!
Masha
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet, Exists As Boolean: Exists = False
Application.DisplayAlerts = False
Application.EnableEvents = True
Set Target = Sheets("Ref").Range("W3")
MsgBox "Changed: " & Target.Address
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Client File" Then
Exists = True
Exit For
End If
Next ws
If Target.Value = 1 And Exists = False Then
Worksheets.Add(after:=Worksheets.Count) = "Client File"
ElseIf Target.Value = 2 And Exists = True Then
Sheets("Client File").Delete
End If
End Sub
I am trying to run a macro based on a cell value. I inserted the below code in the sheet where the cell exists. The code never runs and I added a msgbox just to double check and it doesnt fire up. Can you please help me out?
Many thanks!
Masha
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet, Exists As Boolean: Exists = False
Application.DisplayAlerts = False
Application.EnableEvents = True
Set Target = Sheets("Ref").Range("W3")
MsgBox "Changed: " & Target.Address
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Client File" Then
Exists = True
Exit For
End If
Next ws
If Target.Value = 1 And Exists = False Then
Worksheets.Add(after:=Worksheets.Count) = "Client File"
ElseIf Target.Value = 2 And Exists = True Then
Sheets("Client File").Delete
End If
End Sub