Forum Discussion

NRASA0743's avatar
NRASA0743
Copper Contributor
Jul 20, 2022
Solved

VBAVlookup

Trying to macro Vlookup with a user prompt to manually select range and type columm number, but the code is not working, what am I doing wrong? Sub VbaVlookup() Dim Table As Range Dim Colnum As Int...
  • HansVogelaar's avatar
    HansVogelaar
    Jul 20, 2022

    NRASA0743 

    Sub VbaVlookup()
        Dim Table As Range
        Dim Colnum As Integer
        On Error Resume Next
        Set Table = Application.InputBox(Prompt:="Sample", Type:=8)
        Colnum = Application.InputBox(promt:="Sample", Type:=1)
        Selection.Formula = "=VLOOKUP(A2," & Table.Address(External:=True) & "," & Colnum & ",FALSE)"
    End Sub