VBA Code - Update Code to pull two columns instead of one. Help needed

Realjoshtodd

New Member
Joined
Sep 26, 2017
Messages
34
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim vSourceSheet As Worksheet
Dim VRow As Range
Dim VTargetCounter As Long

If Target.Address = "$A$1" Then
    ' clear out the names in the target column
    Range("A2:A" & Rows.Count).Clear

    ' read through Sheet1 and populate names into Sheet2
    VTargetCounter = 2
    Set vSourceSheet = ThisWorkbook.Worksheets("Sheet1")
    For Each VRow In vSourceSheet.Range("A1:A" & vSourceSheet.Range("A" & vSourceSheet.Rows.Count).End(xlUp).Row)
        If VRow.Cells(1, 1) = Target.Value2 Then
            Target.Cells(VTargetCounter, 1) = VRow.Cells(1, 2)
            VTargetCounter = VTargetCounter + 1
        End If
    Next
End If
End Sub

The code listed currently looks at Sheet2 cell A1, and fills in the all of the names from Sheet1 Column B when Sheet2 cell A1 matches the data in Sheet1 Column A. I need the code to also pull the data in those matches that is Sheet1 Column C and add it in Sheet2 Column B next to the names already populating in Column A on Sheet 2.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
How about
VBA Code:
Target.Cells(VTargetCounter, 1).Resize(,2).Value = VRow.Cells(1, 2).Resize(, 2).Value
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top