SOLVED

How to return a specific value based on a combo box

%3CLINGO-SUB%20id%3D%22lingo-sub-2419228%22%20slang%3D%22en-US%22%3EHow%20to%20return%20a%20specific%20value%20based%20on%20a%20combo%20box%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2419228%22%20slang%3D%22en-US%22%3E%3CP%3EHello!%20I%20have%20an%20activex%20combo%20box%20linked%20to%20a%20list%20of%20services.%20I%20need%20to%20create%20a%20formula%20in%20an%20adjacent%20cell%20that%20reads%20the%20value%20in%20the%20combo%20box%20and%20fills%20in%20the%20appropriate%20price.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20if%20%22CE%22%20is%20chosen%20in%20the%20combo%20box%2C%20the%20adjacent%20cell%20would%20be%20filled%20in%20with%200.022.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENormally%2C%20I%20would%20use%20an%20IF%20statement%20to%20run%20through%20all%20the%20options%20and%20tell%20the%20cell%20what%20value%20to%20return.%20However%2C%20I%20can't%20get%20my%20formula%20to%20recognize%20the%20name%20of%20my%20combo%20box.%20For%20example%2C%20IF(ComboBox1%3D%22CE%22%2C0.022)%20returns%20a%20%23NAME%3F%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat's%20the%20secret%20to%20referencing%20a%20combo%20box%20in%20a%20formula%3F%20And%20is%20there%20a%20better%20formula%20than%20an%20IF%20formula%20to%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2419228%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2419284%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20return%20a%20specific%20value%20based%20on%20a%20combo%20box%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2419284%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1071925%22%20target%3D%22_blank%22%3E%40juliejo%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ESet%20the%20LinkedCell%20property%20of%20the%20combo%20box%20to%20the%20address%20of%20a%20cell%20on%20the%20worksheet%2C%20for%20example%20to%20the%20cell%20under%20the%20combo%20box.%20In%20the%20example%20below%2C%20this%20is%20A2.%20When%20you%20select%20an%20item%20from%20the%20dropdown%20list%2C%20it%20will%20be%20entered%20in%20the%20linked%20cell.%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20list%20with%20the%20services%20in%20the%20first%20column%2C%20and%20the%20corresponding%20prices%20in%20the%20second%20column.%20You%20can%20use%20the%20first%20column%20as%20the%20ListFillRange%20of%20the%20combo%20box.%20In%20the%20example%2C%20it%20is%20E2%3AE6.%3C%2FLI%3E%0A%3CLI%3EIn%20the%20cell%20where%20you%20want%20the%20price%2C%20enter%20a%20VLOOKUP%20formula%20(in%20combination%20with%20IFERROR)%3A%26nbsp%3B%20%3DIFERROR(VLOOKUP(A2%2C%24E%242%3A%24F%246%2C2%2CFALSE)%2C%22%22)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22S0482.png%22%20style%3D%22width%3A%20262px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286596i5D06DAD68C7A58AD%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22S0482.png%22%20alt%3D%22S0482.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22S0483.png%22%20style%3D%22width%3A%20559px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F286597i3CCD863C15AC1DC2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22S0483.png%22%20alt%3D%22S0483.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2419285%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20return%20a%20specific%20value%20based%20on%20a%20combo%20box%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2419285%22%20slang%3D%22en-US%22%3EThat%20formula%20makes%20no%20sense%20to%20me%2C%20but%20it%20works%2C%20so%20I%20don't%20care!%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThanks!%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello! I have an activex combo box linked to a list of services. I need to create a formula in an adjacent cell that reads the value in the combo box and fills in the appropriate price.

 

For example, if "CE" is chosen in the combo box, the adjacent cell would be filled in with 0.022.

 

Normally, I would use an IF statement to run through all the options and tell the cell what value to return. However, I can't get my formula to recognize the name of my combo box. For example, IF(ComboBox1="CE",0.022) returns a #NAME? error.

 

What's the secret to referencing a combo box in a formula? And is there a better formula than an IF formula to do this?

 

Thanks!

3 Replies
best response confirmed by juliejo (Occasional Contributor)
Solution

@juliejo 

 

  1. Set the LinkedCell property of the combo box to the address of a cell on the worksheet, for example to the cell under the combo box. In the example below, this is A2. When you select an item from the dropdown list, it will be entered in the linked cell.
  2. Create a list with the services in the first column, and the corresponding prices in the second column. You can use the first column as the ListFillRange of the combo box. In the example, it is E2:E6.
  3. In the cell where you want the price, enter a VLOOKUP formula (in combination with IFERROR):  =IFERROR(VLOOKUP(A2,$E$2:$F$6,2,FALSE),"")

S0482.pngS0483.png

That formula makes no sense to me, but it works, so I don't care!

Thanks!

@juliejo 

VLOOKUP(A2,$E$2:$F$6,2,FALSE) means:

Take the value of A2, and look for it in the first column of E2:F6, i.e. in E2:E6.

If you find it, return the corresponding value from the 2nd column, i.e. from F2:F6.

FALSE tells Excel to look for an exact match.

If the value of A2 is not found, VLOOKUP will return the error value #N/A.

We wrap VLOOKUP in IFERROR to replace the error value #N/A with the empty string "".