Macro to find cell value in another sheet and copy and paste adjacent row to different sheet

Bran4642

New Member
Joined
Jan 15, 2013
Messages
6
Hello! I have the following code below and it works great but I need to add to it if possible!

I am running a macro in sheet1 on active cell column C and matching it to sheet2 column B cell that works fine. But what I need now is when the match is found on sheet2 column B I need to copy the row adjacent to it in column C and paste it in sheet1 column D beside the active cell I was previously searching. Is this possible if so I could use some help. Below is the code I am using now.

Sub Test()
rngY = ActiveCell.Value
Sheets("Sheet2").Select
Columns("B:B").Select
Selection.Find(What:=rngY, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Select
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about
Code:
Sub Bran4642()
   Dim Fnd As Range
   Dim RngY As Variant
   
   RngY = ActiveCell.Value
   Set Fnd = Sheets("Sheet2").Columns("B:B").Find(RngY, , xlFormulas, xlWhole, xlByRows, xlNext, False, , False)
   If Not Fnd Is Nothing Then ActiveCell.Offset(, 1).Value = Fnd.Offset(, 1).Value
End Sub
 
Upvote 0
Fluff,

Is it possible to run the macro down the whole sheet and it do all that automatically without have to click on the active cell?
 
Upvote 0
Yup, like
Code:
Sub Bran4642()
   Dim Fnd As Range, Cl As Range
   
   With Sheets("sheet1")
      For Each Cl In .Range("C2", .Range("C" & Rows.Count).End(xlUp))
         Set Fnd = Sheets("Sheet2").Columns("B:B").Find(Cl.Value, , xlFormulas, xlWhole, xlByRows, xlNext, False, , False)
         If Not Fnd Is Nothing Then Cl.Offset(, 1).Value = Fnd.Offset(, 1).Value
      Next Cl
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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