Find value on an other worksheet's column and if found, copy the row to that worksheet

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
171
Hi! I need some help!

I Have 2 worksheets.

Sheet "2": The code copies the value from column "G" which is something like A11, A12, A13 etc. up to A316 (a for loop would be great)

Sheet"1": the code search for the copied value on Sheet "1" and finds "A11" in the 65. row

Then the code copies the data from Sheet "2" from column "H" and inserts it in Sheet "1'' in G65.

What I've got:

Code:
Sub FindAndChangeSomeCells()
Dim i As Integer
Dim code As String 'code means the A1, A2, and so on up to 316
Dim rownumber As String
Dim foundcell As Range




For i = 1 To 316 Step 1
code = Cells(i, "G").Value


Set foundcell = Sheets("1").Columns("A:A").Find(What:=code, LookIn:=xlFormulas, _
                                                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                MatchCase:=False, SearchFormat:=False)


Worksheets("1").Activate
foundcell.Select


rownumber = ActiveCell.Row


Sheets("2").Range(i, "H").Value.Copy
Sheets("1").Range(rownumber, "G").Value.Insert


Next

End sub
But it doesn't work. Thank you for your time and effort!
 
Last edited by a moderator:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
How about
Code:
Sub FindAndChangeSomeCells()
Dim i As Integer
Dim code As String 'code means the A1, A2, and so on up to 316
Dim foundcell As Range

For i = 1 To 316 Step 1
   code = Cells(i, "G").Value
   Set foundcell = Sheets("1").Columns("A:A").Find(What:=code, lookIn:=xlFormulas, _
                                                   LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                   MatchCase:=False, SearchFormat:=False)
   
   If Not foundcell Is Nothing Then foundcell.Offset(, 6).Value Range("H" & i).Value
   Set foundcell = Nothing
Next i
End Sub
 
Upvote 0
Thank you Fluff!

If Not foundcell Is Nothing Then foundcell.Offset(, 6).Value Range("H" & i).Value" --> Invalid use of property" and it highlights the Value" word.

Any idea? Thank you for your time again, you are my multiple saver:D

How about
Code:
Sub FindAndChangeSomeCells()
Dim i As Integer
Dim code As String 'code means the A1, A2, and so on up to 316
Dim foundcell As Range

For i = 1 To 316 Step 1
   code = Cells(i, "G").Value
   Set foundcell = Sheets("1").Columns("A:A").Find(What:=code, lookIn:=xlFormulas, _
                                                   LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                   MatchCase:=False, SearchFormat:=False)
   
   If Not foundcell Is Nothing Then foundcell.Offset(, 6).Value Range("H" & i).Value
   Set foundcell = Nothing
Next i
End Sub
 
Upvote 0
Try this

replace this code
If Not foundcell Is Nothing Then foundcell.Offset(, 6).Value Range("H" & i).Value


to this code.
If Not foundcell Is Nothing Then foundcell.Offset(, 6).Value = Range("H" & i).Value
 
Upvote 0
Yup missed the = sign
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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