L
Legacy 290164
Guest
Hello,
I am trying to achieve something similar to a Vlookup I guess.
I want my code to:
Here is what I have come up with reading various bits of this forum:
Sub Lookupforalistofwords()
'
'
'
Dim c As Range
Dim i As Long
Dim x As Long
Dim y As Variant
Dim z As Worksheet
Dim a As Variant
i = 0
x = Selection.Rows.Count
y = Selection.Cells(1, 1)
Set z = ActiveWorkbook.Sheets(1)
Set a = ActiveWorkbook.Sheets(2).Cells(1, 1)
While (i <= x)
Cells.Find(What:=y, After:=a, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveRow.Interior.ColorIndex = 36
ActiveCell.End(xlToRight).PasteSpecial xlPasteValues
y = y.Offset(1)
Wend
End Sub
I am fairly confident I have done a lot wrong and I am really keen to learn from my mistakes.
Any help appreciated!
Natacha.
I am trying to achieve something similar to a Vlookup I guess.
I want my code to:
- Select first cell of range in spreadsheet 2
- Find it in spreadsheet 1
- If found highlight row and paste cell value in adjacent cell
- Move down one cell in range
- Loop until end of range
Here is what I have come up with reading various bits of this forum:
Sub Lookupforalistofwords()
'
'
'
Dim c As Range
Dim i As Long
Dim x As Long
Dim y As Variant
Dim z As Worksheet
Dim a As Variant
i = 0
x = Selection.Rows.Count
y = Selection.Cells(1, 1)
Set z = ActiveWorkbook.Sheets(1)
Set a = ActiveWorkbook.Sheets(2).Cells(1, 1)
While (i <= x)
Cells.Find(What:=y, After:=a, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveRow.Interior.ColorIndex = 36
ActiveCell.End(xlToRight).PasteSpecial xlPasteValues
y = y.Offset(1)
Wend
End Sub
I am fairly confident I have done a lot wrong and I am really keen to learn from my mistakes.
Any help appreciated!
Natacha.