samedi 24 août 2019

Execute a function only if a specific cell contains a specific value

The below code works just great.
Now I only want it to function if cell B2 says "2020".
If cell B2 says "2021", for example, I want the value instead to go to sheet "2021".

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Dim xRtn As Variant
     If Selection.Count = 1 Then
         If Not Intersect(Target, Range("D9:AS20")) Is Nothing Then
             xRtn = Application.InputBox("Insert your value please")
             Sheets("2020").Range(Target.Address).Value = xRtn           
         End If
     End If
End Sub

How can I achieve that?

Aucun commentaire:

Enregistrer un commentaire