Create Macro with User Input Boxes inside an Array Formula

crystal_robinson

New Member
Joined
Aug 27, 2013
Messages
2
I think I kind of have a basic feel of what needs to be done, but am not getting it to work. I need to look up a part number and PO number on tab one, and match it to the part and po columns in the table on tab 2, returning the value pieces shipped, from the table from tab 2. I have been using the formula by typing it manually, and no one else in my office is capable of that. Is there a way to make it a macro?

Formula is
=INDEX(Table1,MATCH(C2092&D2092,Table1[Column1]&Table1[Column2],0),7)

I need a macro
{=INDEX("select table array",MATCH("select part"&"select PO","select parts column"&"select PO column",0)"select column number")}


This is my macro, in which I receive an error at the last part for selecting column number and even if I make that a constant I am getting #NAME error

Code:
Sub LookupValuesa()
'
' LookupValues Macro
    Set myRange = Application.InputBox( _
    prompt:="Select a Range", Type:=8)
    
    Set myPart = Application.InputBox( _
    prompt:="Select Part Number To Look Up", Type:=8)
    
    Set myPO = Application.InputBox( _
    prompt:="Select PO Number To Look Up", Type:=8)
    
    Set myPartC = Application.InputBox( _
    prompt:="Select Parts Column in Data Worksheet", Type:=8)
    
    Set myPOC = Application.InputBox( _
    prompt:="Select PO Column in Data Worksheet", Type:=8)
    
    Selection.FormulaArray = _
        "=INDEX(myRange,MATCH(myPart&myPO,myPartC&myPOC,0),7)"
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try the code below. Note that when you enter the columns in the input box they should be entered as "A:A" instead of just "A". Another note is make sure when you enter the initial range the starting row is always 1, for example "A1:L20". If you enter "A2:L20", the formula will give you an incorrect answer.

Code:
Sub LookupValuesa()
'
' LookupValues Macro


    Dim myPart As Long
    Dim myPO As Long
    Dim myRange As Range
    Dim myPartC As Range
    Dim myPOC As Range
    
    Set myRange = Application.InputBox(prompt:="Select a Range", Type:=8)
    
    myPart = Application.InputBox(prompt:="Select Part Number To Look Up")
    
    myPO = Application.InputBox(prompt:="Select PO Number To Look Up")
    
    Set myPartC = Application.InputBox(prompt:="Select Parts Column in Data Worksheet", Type:=8)
    
    Set myPOC = Application.InputBox(prompt:="Select PO Column in Data Worksheet", Type:=8)
    
    Selection.FormulaArray = "=INDEX(" & myRange.Address & ",MATCH(" & myPart & "&" & myPO & "," & myPartC.Address & "&" & myPOC.Address & ",0),7)"
End Sub
 
Upvote 0
I tried it and am getting an error at the input PO number part. I am just clicking on the PO number I need. Do I need to manually type everything into the input box? Im sorry I dont know what I am doing wrong. This is where its highlighted in the macro. Thanks for all your help.

myPO = Application.InputBox(prompt:="Select PO Number To Look Up")
 
Upvote 0
try this, haven't tested it so let me know if it works

Code:
Sub LookupValuesa()
'
' LookupValues Macro




    Dim myPart As Range
    Dim myPO As Range
    Dim myRange As Range
    Dim myPartC As Range
    Dim myPOC As Range
    
    Set myRange = Application.InputBox(prompt:="Select a Range", Type:=8)
    
    Set myPart = Application.InputBox(prompt:="Select Part Number To Look Up", Type:=8)
    
    Set myPO = Application.InputBox(prompt:="Select PO Number To Look Up", Type:=8)
    
    Set myPartC = Application.InputBox(prompt:="Select Parts Column in Data Worksheet", Type:=8)
    
    Set myPOC = Application.InputBox(prompt:="Select PO Column in Data Worksheet", Type:=8)
    
    Selection.FormulaArray = "=INDEX(" & myRange.Address & ",MATCH(" & myPart & "&" & myPO & "," & myPartC.Address & "&" & myPOC.Address & ",0),7)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,139
Members
452,381
Latest member
Nova88

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