Code Particular Strings As Numbers, Then Sum Numbers

DerekK

Board Regular
Joined
Jun 18, 2007
Messages
90
Office Version
  1. 2003 or older
Platform
  1. Windows
Hello,

I'm trying to assign numerical values to a set of particular strings; and then add the numbers.

It would work something like this --

Category A = 0
Category B = 1
Category C = 2
Category D = 3

-- with "Category A", "Category B" &c. in a dropdown list.

Then, a cell with this formula --

=SUM(Category B,Category C)

--returns 3.

Hope you can help!

Sincerely,



Derek
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This works based on your somewhat vague description, cos I can see you expanding your request and this no longer working, so your description isn't specific enough.
But this will work on what you've said.

Use a Named Range

1. Put the values 0 1 2 3 in separate cells A1:D1
2. Use four named ranges CategoryA CategoryB CategoryC CategoryD with the named ranges representing A1 B1 C1 D1
3. Now you should be able to enter

SUM(CategoryB, CategoryC)

and end up with 3

However, this is not a flexible solution.
It is a working solution based on what you've asked so you probably need to explain things fully, like how many categories there are likely to be etc

I suspect a better way would be to use a SUM on a VLOOKUP or INDEX/MATCH as you'll probably have much more than 4 catagories.

But the onus is on you to explain fully to get the results you want.
 
Last edited:
Upvote 0
Another option

<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:105.5px;" /><col style="width:76.04px;" /><col style="width:28.51px;" /><col style="width:48.48px;" /><col style="width:236.67px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >CATEGORY</td><td >VALUE</td><td > </td><td > </td><td >STRINGS IN A DROPDOWN LIST</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category A</td><td style="text-align:right; ">0</td><td > </td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category B</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category B</td><td style="text-align:right; ">1</td><td > </td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category C</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category C</td><td style="text-align:right; ">2</td><td > </td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category E</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category D</td><td style="text-align:right; ">3</td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category E</td><td style="text-align:right; ">4</td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category F</td><td style="text-align:right; ">5</td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td style="color:#333333; font-family:Verdana; font-size:9pt; ">Category G</td><td style="text-align:right; ">6</td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td > </td><td > </td><td > </td><td >SUM</td><td style="text-align:right; ">7</td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Array Formula</td></tr><tr><td >E11</td><td >{=SUM(IF(ISNUMBER(MATCH(A2:A8,E2:E8,0)),B2:B8))}</td></tr></table></td></tr></table>

Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself
 
Upvote 0
Thank you for the replies.

I wound up using =SUM(LOOKUP(A2,{"Category A";"Category B";"Category C"},{1;2;3}),LOOKUP(B2,{...et cetera with the dropdown list. It's not pretty but I was more concerned that the users would accidentally mess up or delete any table.
 
Upvote 0
Thank you for the replies.

I wound up using =SUM(LOOKUP(A2,{"Category A";"Category B";"Category C"},{1;2;3}),LOOKUP(B2,{...et cetera with the dropdown list. It's not pretty but I was more concerned that the users would accidentally mess up or delete any table.

Is your formula practical if you have only 3 categories, but if you have 10 or 20?
Accidents can occur on a table or on the entire sheet with formulas.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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