Hello, I'm very much a beginner in VBA coding. What I wanted to do was to make a macro to vlookup a certain column in table1 to be pasted to table2, and to use input boxes so users can specify which column they want to vlookup.
Problem is, the code can't seem to recognize that I want a range of cells from the user and not just one cell for the reference. The table_lookup value also only took in one cell even after selecting a range of cells in the input boxes. I would appreciate any help regarding this.
This is my code.
Problem is, the code can't seem to recognize that I want a range of cells from the user and not just one cell for the reference. The table_lookup value also only took in one cell even after selecting a range of cells in the input boxes. I would appreciate any help regarding this.
This is my code.
VBA Code:
Sub VLOOKUPtry()
Dim reff As String
Dim lookuptable As Range
Dim columnin As Integer
Dim exactma As Boolean
Set lookuptable = Application.Selection
reff = Application.InputBox("What is your reference?")
lookuptable = Application.InputBox("What is the range of the data?")
columnin = Application.InputBox("What number is the column in from the left?")
exactma = Application.InputBox("If exact match, press 0")
ActiveCell.FormulaR1C1 = "=VLOOKUP(""" & reff & """, """ & lookuptable.Address & """, """ & columin & """, """ & exactma & """)"
End Sub