Worksheet_Change(ByVal Target As Range) throws error

  • trying to have cell value change based on another cell value change


    code below throws this error


    [ATTACH=JSON]{"data-align":"none","data-size":"large","data-attachmentid":1221701}[/ATTACH]


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim intersection As Range
        Set intersection = Intersect(Target, Worksheets("Sheet1").Range("G1"))
        If Not intersection Is Nothing Then
            If Worksheets("Sheet1").Range("G1").Value = Worksheets("Sheet20").Range("K2").Value Then
            Worksheets("Sheet1").Range("F2").Value = Worksheets("Sheet20").Range("I2").Value
            End If
        End If
    End Sub
  • Give this a try:


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target = Range("G1") Then
            If Target.Value2 = Sheets("Sheet20").Range("K2") Then
                Sheets("Sheet1").Range("F2") = Sheets("Sheet20").Range("I2")
            End If
        End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!