Finding value in a column in another sheet and bring in another worksheet by offset

rdev

Active Member
Joined
Dec 3, 2007
Messages
273
I have the following data in sheet1 in
Column A Column B
Nam-Biz Region
Dev FG
Samy GR
Lapo HP

I need to pull corresponding values in sheet 2 for each occurrence of values in column A in Column A in Sheet 2 . For example

In Sheet 2

Name Biz Region
Samy GR
Dev FG
Samy GR

I need help with a macro which can do that
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
rdev,

If I understand you correctly, then here is a macro solution for you to consider.

Sample raw data worksheets:


Excel 2007
AB
1Nam-BizRegion
2DevFG
3SamyGR
4LapoHP
5
Sheet1



Excel 2007
AB
1Nam-BizRegion
2Samy
3Dev
4Samy
5
Sheet2


And, after the macro:


Excel 2007
AB
1Nam-BizRegion
2SamyGR
3DevFG
4SamyGR
5
Sheet2


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub rdev()
' hiker95, 01/13/2017, ME985590
Dim w1 As Worksheet, w2 As Worksheet
Dim n As Range, r As Range
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w2
  For Each n In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set r = w1.Columns(1).Find(n.Value, LookAt:=xlWhole)
    If Not r Is Nothing Then
      n.Offset(, 1).Value = w1.Cells(r.Row, 2).Value
    End If
  Next n
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the rdev macro.
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,262
Members
448,953
Latest member
Dutchie_1

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