Forum Discussion

Change99's avatar
Change99
Brass Contributor
Feb 16, 2021
Solved

When cell value changes, copy the information to a new worksheet to multiple columns

    I would like to have Excel copy the changed values of one cell to multiple columns on a another sheet.   1) B2 has a value. I change the value. It copies the value to sheet 2. I then change t...
  • HansVogelaar's avatar
    Feb 16, 2021

    Change99 

    Like this:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng1 As Range
        Dim rng2 As Range
        Dim c As Long
        
        If Intersect(Range("B2:B" & Rows.Count), Target) Is Nothing Then
            Exit Sub
        End If
        
        On Error GoTo ErrHandler
        Application.EnableEvents = False
        For Each rng1 In Intersect(Range("B2:B" & Rows.Count), Target)
            c = rng1.Row
            With Worksheets("Sheet 2")
                Set rng2 = .Cells(.Rows.Count, c).End(xlUp).Offset(1)
            End With
            rng2.Value = rng1.Value
        Next rng1
        
    ExitHandler:
        Application.EnableEvents = True
        Exit Sub
        
    ErrHandler:
        MsgBox Err.Description, vbExclamation
        Resume ExitHandler
    End Sub

Resources