I have crossposted a similar question at https://www.excelforum.com/excel-pr...lues-instead-of-looping-through-combobox.html.
I am trying to learn how to loop through a named range and a range and then using Application.Vlookup, Application.Rank and Application.Index, Application.Match on the named range/range.
At the moment I am using a for loop to iterate through an ActiveX ComboBox to perform Vlookups and I would like to run Application.Vlookup on a range instead to see if it is faster then accessing the value through the ComboBox.
MyRange contains 40 cities and I would like to Vlookup 5 values for each city, rank each value and then finally write the results to my spreadsheet, with the results of the vlookup, the rank and maybe index & match lookup also for more flexible lookups.
If possible I would also like to learn how to store the results in an array?
This code I got working and I understand it.
This code I don't understand?
I am grateful for all help I can get!
I am trying to learn how to loop through a named range and a range and then using Application.Vlookup, Application.Rank and Application.Index, Application.Match on the named range/range.
At the moment I am using a for loop to iterate through an ActiveX ComboBox to perform Vlookups and I would like to run Application.Vlookup on a range instead to see if it is faster then accessing the value through the ComboBox.
MyRange contains 40 cities and I would like to Vlookup 5 values for each city, rank each value and then finally write the results to my spreadsheet, with the results of the vlookup, the rank and maybe index & match lookup also for more flexible lookups.
If possible I would also like to learn how to store the results in an array?
This code I got working and I understand it.
Code:
Sheets("Dash).Range("M18") = Application.WorksheetFunction.VLookup(Sheets("Dash").Range("F5"), Sheets("Data").Range("A1:PY305"), 2, False)
This code I don't understand?
Code:
Sub WantToBeLooped()
Dim ws As Worksheet
Dim i As Integer
Dim j As Integer
Dim myRange as Range
Set myRange = ???
Set ws = ThisWorkbook.Sheets("Dash")
Set ws1 = ThisWorkbook.Sheets("Data")
LastRow = ThisWorkbook.Sheets("Dash").Range("A" & Rows.Count).End(xlUp).Row
With ws
' I don't understand how this works
For j = 1 To Lastrow
For i = 1 To LastColumns
On Error Resume Next
Sheets("Dash).Range(i, j) = Application.WorksheetFunction.VLookup(Sheets("Dash").Range(myRange, i), Sheets("Data").Range("A1:PY305"), 2, False)
Next i
Next j
End With
End Sub
I am grateful for all help I can get!