Solved

Summing selections from a drop down list

Posted on 2013-05-25
2
303 Views
Last Modified: 2013-05-26
I have three cells. Each have the same drop down box (list). Each selection within that list is equal to a value (PN1 is 1, PN2 is 2, PN3 is 3..., PN8 is 8).

The fourth cell displays the summation of cells 1-3.

How would a macro be written to accomplish that?

Thanks in advance
0
Comment
Question by:dgd1212
2 Comments
 
LVL 14

Accepted Solution

by:
Faustulus earned 500 total points
ID: 39197140
Would something like this work for you?
Range("D4").Value =  WorksheetFunction.Sum(Range("A1:C1"))

Open in new window

Here D4 is the fourth cell you mentioned. If the cells aren't joined you can enumerate the three cells to be summed. WorksheetFunction.Sum(Range("A1,B2,C3"))

If the job is to determine which selection has been made in each of the drop-downs you would need to tell a little more about the controls' nature. The easiest way would be to read the control's ListIndex property. This property returns 0 for the first choice, 1 for the second and so on. Therefore, the value you wish to assign is ListIndex + 1 and you can sum them up in a loop like,
For i = 1 to 3
    n = n + Control(i).Listindex + 1
Next i
The trouble is that not all drop-downs have the ListIndex property and, even if the property exists, different types of controls must be addressed using slightly (or grossly) different syntax. If you aren't sure of the type of your control I suggest you post your worksheet with the 3 drop-downs in it.
0
 
LVL 80

Expert Comment

by:byundt
ID: 39197948
You might use an array-entered formula for your sum instead of using a macro:
=SUM(IFERROR(MATCH(A1:A3,DropdownChoices,0),))

To array-enter a formula:
1. Paste the formula in the formula bar (or click in the formula bar)
2. Hold the Control and Shift keys down
3. Hit Enter, then release all three keys
Excel should respond by adding curly braces { } surrounding your formula. If not, repeat steps 1 to 3.
SumOfDropdownChoicesQ28139167.xlsx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now