ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add loop to Vlookup (https://www.excelbanter.com/excel-programming/387708-add-loop-vlookup.html)

Les

Add loop to Vlookup
 
Hi all, i have got the following code that i need to loop with can somebody
please show me how to alter the code....
It works great except i need it to loop down all numbers in column A which
will be variable in length


Sub VLUp()
Dim LookUpTable As Range, LookUpCell As Range
Dim res As String, myRange As Range

Set LookUpTable =
Workbooks("PU0907LCS.xls").Worksheets("LCS").Range ("LCS")
Set LookUpCell = Workbooks("90IH0709.xls").Worksheets("KTL").Range( "A10")

res = Application.VLookup(LookUpCell.Value, LookUpTable, 7, False)
ActiveCell = res
res = Application.VLookup(LookUpCell.Value, LookUpTable, 2, False)
ActiveCell.Offset(0, 2) = res
res = Application.VLookup(LookUpCell.Value, LookUpTable, 8, False)
ActiveCell.Offset(0, 3) = res


End Sub

--
Les

Allen Lance

Add loop to Vlookup
 
Les,

There's a few different ways to loop through your active cells.

Here's one simple way of doing that.....

Dim MyRow as long

For MyRow = 1 to Range("A65536").End(xlup).Row

'Put your code in here
'use MyRow as your Row identifier
' For Example Cells(MyRow,1).Value = "Column A of Row MyRow"

Next MyRow

I hope this points you in the right direction.

Allen




All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com