Populate to Sheet 2 from information on Sheet 1

NY_Rican

New Member
Joined
Jan 13, 2022
Messages
18
Office Version
  1. 2021
Platform
  1. Windows
Sheet 1 has column A, with a list of names...column B has the list of ID numbers that correspond to each name. Sheet 2 Column A has a data validation list, which was created from the names on Sheet 1, column A. Sheet 2 column B is blank. I would like to choose a name from Column A in Sheet 2 and have the corresponding ID number from Column B in Sheet 1, populate to Column B in Sheet 2. I hope I'm clear. Thank you in advance.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Sheet2 and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column A of Sheet2.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Dim rName As Range
    Set rName = Sheets("Sheet1").Range("A:A").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not rName Is Nothing Then
        Target.Offset(, 1) = rName.Offset(, 1)
    End If
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Sheet2 and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in column A of Sheet2.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Dim rName As Range
    Set rName = Sheets("Sheet1").Range("A:A").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not rName Is Nothing Then
        Target.Offset(, 1) = rName.Offset(, 1)
    End If
End Sub
Oh yes !!! I have the Mumps !!!! Thank you brother
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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