VBA Vlookup to return value LEFT of table

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
I posted this up a few minutes ago, but for some reason the post fails when you click on it...I didn't put anything spurious in there...very strange

I'm basically able to do a VLOOKUP in VBA using:

Code:
filetype = Application.WorksheetFunction.VLookup(filename, Sheets("FilesInProject").Range("B2:D1000"), 1, False)

but I now also need to find the corresponding value in column A...

How can I do this?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
My brain hurts... I've had a look at that code and I can't work out where to go next

Code:
Dim i As Integer
Dim filename_to_match As String
Dim filetype As String
Dim lastrow As Long
Dim lastrowB As Long


lastrow = Sheets("FilesInProject").Range("H" & Rows.Count).End(xlUp).Row
lastrowB = Sheets("FilesInProject").Range("B" & Rows.Count).End(xlUp).Row

filename_to_match = Sheets("FilesInProject").Cells(1, 8).Value 'cell H1

so Ineed to match the value of H1 'filename_to_match' with the same value in column B and then return the value in column A on the same row

confused :S
 
Last edited:
Upvote 0
The scripting dictionary in VBA is more efficient than vlookup, but with only 1000 rows, you can try:


Excel 2010
AB
1NumberName
23B
38Q
47O
52N
61C
73Z
83A
99S
102D
111F
12
13
14O7
Sheet7
Cell Formulas
RangeFormula
B14=VLOOKUP(A14,CHOOSE({1,2},$B$2:$B$11,$A$2:$A$11),2,0)
 
Last edited:
Upvote 0
I think I have understood what you atrying to do , try this:
Code:
Dim i As IntegerDim filename_to_match As String
Dim filetype As String
Dim lastrow As Long
Dim lastrowB As Long




lastrow = Sheets("FilesInProject").Range("H" & Rows.Count).End(xlUp).Row




lastrowB = Sheets("FilesInProject").Range("B" & Rows.Count).End(xlUp).Row
' load all of the data from file in projenct into a varaint array
inarr = Worksheets("Filesinproject").Range(Cells(1, 1), Cells(lastrowB, 8))


filename_to_match = Sheets("FilesInProject").Cells(1, 8).Value 'cell H1


' loop down column B looking ofr a match
For i = 1 To lastrowB
 If filename_to_match = inarr(i, 2) Then ' column B in the variant array
  ' we found the match
   filetype = inarr(i, 1) ' this is column A
  Exit For
 End If
Next i

Note , totally untested
 
Upvote 0
offthelip, you are a star! Works perfectly mate!

thanks very much :)
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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