match command in vlookup

Aqsa Butt

New Member
Joined
Sep 12, 2018
Messages
1
hi, i am new in excel vba i am trying to write a code that will use a dynamic value as the column index
i googled it and reached at this code
Dim FileName As String
Dim value As String
Dim value2 As Double
Dim value3 As Double
Dim wbName As String, wb As Workbook, ws As Worksheet
Application.ScreenUpdating = False
txt = "F:\Sapphire\excel work\MISExecutiveSummaryAugust2018Macros.xlsm"
If Dir(txt) = "" Then
MsgBox txt & " does not exist"
Else
Set wb = Workbooks.Open(txt)
On Error Resume Next
Set ws = wb.Sheets("ES Report 1")
If Not ws Is Nothing Then
MsgBox ws.Range("C23")
value = Cells(23, 3)
MsgBox (value)
wb.Close
Cells(18, 1) = value
Else
MsgBox ws.Name & " does not exist"
End If
Err.Clear
End If
Application.ScreenUpdating = True
value3 = InputBox("Enter value you want to look for")
MsgBox value3
Cells(17, 2) = value3
value2 = Application.vlookup(value, Sheet1.Range("A1:D14"), Match(value3, Range("A2:A13"), 0), False)
MsgBox ("value2 is " & value2)


it is working good except that it show the error that Sub or Function is not defined and highlights the "Match"
i dont know how to solve this
thanks in advance
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,110
Office Version
  1. 365
Platform
  1. Windows
You would need to use application.match or worksheetfunction.match. You havent specified your sheet name for the range also. Its a little weird. The match can potentially return a number from 1 to 12. Your lookup range has only 4 columns. This will error if the match produces any number greater than 4. Id assume this formula is not as intended.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,146
Messages
5,527,079
Members
409,743
Latest member
sukuto20

This Week's Hot Topics

Top