If a cell contains specific text, then return a specific answer

veronicaandtodd

New Member
Joined
Mar 10, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create a formula that will look for a size in a specific cell and then return a cost in another cell. For example, sizes S-XL cost $0; sizes 1X-3X cost $2.14; and sizes 4X-5X cost $4.28. This is what I came up with but it only works for sizes 1X-5X. The formula returns an answer of 4.28 for sizes S-XL. Any help would be appreciated!
=+LOOKUP(B11,{"S","M","L","XL","1X","2X","3X","4X","5X"},{0,0,0,0,2.14,2.14,2.14,4.28,4.28})
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
With the Lookup function, the values in the lookup vector must be in ascending order. Therefore:
Book1
AB
1SizeCost
2S0
3M0
4L0
5XL0
61X2.14
72X2.14
83X2.14
94X4.28
105X4.28
Sheet1
Cell Formulas
RangeFormula
B2:B10B2=LOOKUP(A2,{"1X","2X","3X","4X","5X","L","M","S","XL"},{2.14,2.14,2.14,4.28,4.28,0,0,0,0})
 
Upvote 0
Solution
With the Lookup function, the values in the lookup vector must be in ascending order. Therefore:
Book1
AB
1SizeCost
2S0
3M0
4L0
5XL0
61X2.14
72X2.14
83X2.14
94X4.28
105X4.28
Sheet1
Cell Formulas
RangeFormula
B2:B10B2=LOOKUP(A2,{"1X","2X","3X","4X","5X","L","M","S","XL"},{2.14,2.14,2.14,4.28,4.28,0,0,0,0})
That worked. Thanks so much!
 
Upvote 0
Welcome to the MrExcel board!

Another option would be to put this shorter formula in the top cell and it will fill all the results for you without the need to copy it down.

24 03 11.xlsm
AB
1SizeCost
2S0
3M0
4L0
5XL0
61X2.14
72X2.14
83X2.14
94X4.28
105X4.28
Lookup Cost
Cell Formulas
RangeFormula
B2:B10B2=LOOKUP(IFERROR(--LEFT(A2:A10,1),0),{0,1,4},{0,2.14,4.28})
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,215,701
Messages
6,126,289
Members
449,308
Latest member
VerifiedBleachersAttendee

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