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.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Target.Cells(VTargetCounter, 1).Resize(,2).Value = VRow.Cells(1, 2).Resize(, 2).Value
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,584
Messages
5,597,026
Members
414,116
Latest member
sfullnet

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
Top