Loop with values in Column D in Sheet 2 to find Values anywhere on Sheet 3 and Paste to adjacent Cell E in Sheet 1

Timjan

Board Regular
Joined
Oct 5, 2016
Messages
63
Hi dear Members,

The syntax for creating a loop to use values in Column D in Sheet 2 to find Values anywhere on Sheet 3 and Paste to adjacent Cell E in Sheet 1 eludes me.

Could anyone point me in the right direction, please?:confused:

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
This Code below is what I have at the moment but it only returns the correct Value in Sheet 2 Column E. Why does it not do the remainder Cells in Column D in Sheet 2?

Code:
Sub findCellVal()
Dim c As Range
Sheet1.Activate
Dim ra As Range
Dim lr As Long

lr = Sheet2.Cells(Rows.Count, 4).End(xlUp).Row
Set ra = Sheet3.Range("A:D")
 
For i = 2 To lr
    Sheet3.Activate

    Set ra = Cells.Find(what:=Sheet3.Range("D2"), LookIn:=xlFormulas, LookAt _
        :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)

    If ra Is Nothing Then
        MsgBox "not found"
        Else
        Sheet2.Range("E2") = ra.Value
    End If
Next i
End Sub

I know it is a simple fix, but I just can not see the wood from the trees right now.:(
 
Upvote 0
Forget the code for a moment, can you explain with examples what you want to do?
 
Upvote 0
Hi DanteAmor,

I will try to give you some "Screen Shots"

I can not do Screen Shots.:(

This is Sheet 2

ABCDE
1 Search valueResult
2 AppleApple
3 BananaBanana
4 CherryCherry
5 OrangeOrange
6 AvoAvo
7 PeanutsPeanuts

<colgroup><col style="mso-width-source:userset;mso-width-alt:2596;width:53pt" width="71"> <col style="mso-width-source:userset;mso-width-alt:2560;width:53pt" width="70"> <col style="mso-width-source:userset;mso-width-alt:2998;width:62pt" width="82"> <col style="mso-width-source:userset;mso-width-alt:3693;width:76pt" width="101"> <col style="mso-width-source:userset;mso-width-alt:2633;width:54pt" width="72"> </colgroup><tbody>
</tbody>





This is Sheet 3

ABCDE
1
2
3Apple
4Peanuts
5Avo
6Orange
7Banana
8
9
10Cherry
11
12

<tbody>
</tbody>
The aim is to use the data in Column D in Sheet2 to find that same value in sheet 3 and paste it to Column E in Sheet 2.

HTH:)

<tbody>
</tbody>
 
Last edited:
Upvote 0
Try this

Code:
Sub findCellVal()
  Dim c As Range, f As Range
  For Each c In Sheet2.Range("D2", Sheet2.Range("D" & Rows.Count).End(xlUp))
    Set f = Sheet3.Cells.Find(c, , xlValues, xlWhole)
    If Not f Is Nothing Then
      c.Offset(, 1).Value = c.Value
    Else
      c.Offset(, 1).Value = "Not found"
    End If
  Next
End Sub
 
Upvote 0
DanteAmor,

Thank you so much. It is a hit! :)

Would it be possible to add the Cell Address of the Values found in sheet 3 to say Column F in sheet 2?

Bowled you with this one! LOL;)
 
Upvote 0
Would it be possible to add the Cell Address of the Values found in sheet 3 to say Column F in sheet 2?

After this line
Code:
c.Offset(, 1).Value = c.Value

Add this line
Code:
c.Offset(, 2).Value = c.Address
 
Upvote 0
Hi DanteAmor,

Thank you for your time and help.

Code:
c.Offset(, 2).Value = c.Address

Returns the Cells address of column D in Sheet2, instead of the respective Cell Addresses in Sheet3 where the values were found.
 
Upvote 0
Sorry

Try this

Code:
c.Offset(, 2).Value = [B]f[/B].Address
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
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