excelvbaworksheet-function

How do I Target Multiple cell inputs Worksheet_Change that will have different outcomes?


Sub Worksheet_Change(ByVal Target As Range)
    Dim RR As Range, N As Long, v As Variant
    
    Set RR = Intersect(Target, Range("A2"))
    If RR Is Nothing Then Exit Sub

    v = Range("A2").Text
    N = Cells(Rows.Count, "A").End(xlUp).Row + 1
    Application.EnableEvents = False
        Range("A" & N).Value = v
    Application.EnableEvents = True
    
    
End Sub

 Sub B_Worksheet_Change(ByVal Target As Range)
    Dim TT As Range, Z As Long, v As Variant
    
    Set TT = Intersect(Target, Range("B2"))
    If TT Is Nothing Then Exit Sub

    A = Range("B2").Text
    Z = Cells(Rows.Count, "B").End(xlUp).Row + 1
    Application.EnableEvents = False
        Range("B" & Z).Value = A
    Application.EnableEvents = True
    
    
End Sub

Attached is a photo of the excel spreadsheet and VBA Code. I am able to copy the Inputs received from Column A Row 2 under "Agent Name" to automatically save onto the "Master list below in it's perspective column".

I would like Excel to automatically copy New Inputs received under Agent. deal type, agent email address, telephone #, and Property Address to automatically save as a memory list below.

Worksheet_Change seems to be for one variable input change, how do I track multiple ones that will have different end parameters.

Essentially I want all New Variable inputted in Row 2 to be saved below in Rows 11 and downward... and create a list of saved inputs made.

Thank You for your assistance I'm new to VBA coding btw.

Click Here Excel Spreadsheet & Code Thus Far

I tried varies troubleshooting but im new to VBA and can't seem to figure it out. I joined an automation Discord as well for extra assistance, and googled the issue.


Solution

  • You can do it this way:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range, c As Range
        
        Set rng = Application.Intersect(Target, Me.Range("A2:E2")) 'check range of interest
        If rng Is Nothing Then Exit Sub 'exit if no updates in row2
        
        For Each c In rng.Cells        'loop all affected cells
            If Len(c.Value) > 0 Then   'cell has any value?
                'add the value to the list below
                Me.Cells(Rows.Count, c.Column).End(xlUp).Offset(1) = c.Value
            End If
        Next c
    End Sub