I have 2 worksheets (Mysheet and Sheet1)
In Mysheet I have some partial text which the product description (column D) in Sheet1 has in it.
I want to loop through each items in Mysheet, locate each cell in Sheet1's Product Description (Col. D) that has that text, and then write the text from Mysheet in Sheet1's Col. C against each cell that contains that text.
I have this code but it is not giving desired results
Sub FindAndWrite()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim cell As Range, searchRange As Range, foundRange As Range
Set ws1 = ThisWorkbook.Sheets("Mysheet")
Set ws2 = ThisWorkbook.Sheets("Sheet1")
Set searchRange = ws1.Range("A1:A10")
For Each cell In searchRange
Set foundRange = ws2.Range("D:D").Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
If Not foundRange Is Nothing Then '
foundRange.Offset(0, -1).Value = "found"
End If
Next cell
End Sub
Please help.
In Mysheet I have some partial text which the product description (column D) in Sheet1 has in it.
I want to loop through each items in Mysheet, locate each cell in Sheet1's Product Description (Col. D) that has that text, and then write the text from Mysheet in Sheet1's Col. C against each cell that contains that text.
I have this code but it is not giving desired results
Sub FindAndWrite()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim cell As Range, searchRange As Range, foundRange As Range
Set ws1 = ThisWorkbook.Sheets("Mysheet")
Set ws2 = ThisWorkbook.Sheets("Sheet1")
Set searchRange = ws1.Range("A1:A10")
For Each cell In searchRange
Set foundRange = ws2.Range("D:D").Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
If Not foundRange Is Nothing Then '
foundRange.Offset(0, -1).Value = "found"
End If
Next cell
End Sub
Please help.
Book12.xlsm | |||
---|---|---|---|
C | |||
1 | Found Col | ||
Sheet1 |
Book12.xlsm | |||
---|---|---|---|
A | |||
2 | 200 Silicone Fluid 200 cSt | ||
Mysheet |