Hello,
I am trying to get the following to work:
I have a table with values in it. Each value is a sum of other values which are located on different sheets in the same excel workbook. In order to add the values for each cell I am using several SUM() matrix formulas which works great.
What I would like to do is when I click on a value in my table, I would like to get some sort of pop-up box that lists all the values that were used in summing up to that value.
For example the table goes from K8:V16
The value in T10 is 1200, which is the sum of several other numbers
The sum of T10 actually is:
Bus Ticket 20 EUR
Restaurant 200 EUR
Computer 900 EUR
Documents 80 EUR
The reason the matrix formula sums all of this up is because all the expenses occurred on the same day (e.g. Oct 1, 2010)
So what I would like is that when I click T10, that I get a list of these expenses in a pop-up box (showing a list similar to the one above). And of course, if I click T11, I should get a different list, just as if I click U10 or any other cell in the table I should get the values and names of the expenses that add up to that cell.
I was thinking of using MsgBox, but I don't know how to:
1) trigger a VBA script through a single click on a cell
2) recognize which cell is triggering the event
3) using the information in the cell to find in adjacent sheets which values were used to add up to the total
4) instead of 3 above, or in addition: I know how to use VLOOKUP, which gives me ONE value in return, but don't know what to use to get all values...maybe using a loop?
Thank you in advance. I know that this is probably not easy, maybe we can tackle it step by step, and I will test and see.
I am using Excel 2010, but if possible would like to write a script that works on Excel 2003 also.
Cheers,
SSDLFUN
Last edited by ssdlfun; 11-04-2010 at 08:18 PM.
Please post a sample file.
Can we ask why you're not using a Pivot Table which would seem to offer you all of the functionality you require by default ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Thank you for the reply.
Attached you can find a "Sample.xlsx" file which should almost be self explanatory.
What I am trying to do is the following:
1) On sheet "Summary 2010 (new)" i would like to click on cell M10 and see a pop-up with the summary of what charges are adding up to that value
2) I would like to be able to click on any cell in that table and get the same effect.
In the case of M10 I would like to see a pop-up box next (or close to the cell) -- i.e. relative to the cell with the following information:John - 15 EURIf I clicked on a different cell I would like to get the summary of that cell instead.
- 1 Oct - Taxi with friend - 15 EUR
Peter - 42 EUR
- 1 Oct - Returning from Lunch - 10 EUR
- 1 Oct - Taxi for a friend - 15 EUR
- 5 Oct - Taxi going to lunch - 10 EUR
- 5 Oct - Taxi coming from lunch - 7 EUR
Total - 57 EUR
Please ask if it is not clear, like that I can try to explain better.
The reason I am not using Pivot Tables is because the attached file is a simplification of what I am doing and the matrix formulas that I am using are really not a problem for me. I am just trying to get a pop-up box with this information next to the relevant cell.
Thank you for your help!!![]()
If you designed the spreadsheet properly you could use Donkey's suggestion
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
I have to say that from a drill down perspective pursuing Pivots is something of a no brainer irrespective of your ability with formulae - you are in essence looking to recreate the wheel.
(the 3D nature of your set up will not lend itself to this task however... Multi Consolidation Pivots have limited flexibility - from a design perspective it is always better to have a single repository)
I would also take this opportunity to state that matrices of Arrays are bad news (always) ... it is likely that they will come back to haunt you from a performance perspective.
IMO (FWIW) you should add a key to your individual sheets such that you can revert to the much more efficient SUMIF* with concatenated criteria compared to concatenated key
*SUMIFS obviously excluded given backwards compatibility requirements
In terms of drill down without Pivots - you're looking at:
the above is not something I have time to do myself presently but should hopefully act as a pointer if nothing else1 - using the Double Click Event to trap the intent
2 - iterating all appropriate worksheets
3 - applying Filters to each iterate sheet based on intersecting "Header" values of the Target Cell
4 - copying the visible cells (post filter less header) and writing to the newly created sheet (obviously adding each subset after the other so as not to overwrite)
Last edited by DonkeyOte; 11-05-2010 at 07:36 AM. Reason: missing all important word in narrative...
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
@royUK: not sure how to design the spreadsheet "properly", since the "John" and "Peter" sheets are going to be filled out by different people. I guess I could consolidate them into one sheet and then use the Pivot Table, but I am trying to keep the interface as is. Regardless, I am not sure how a Pivot Table gives you the summary of the summed number in a pop-up? Is there a feature I am missing?
@Donkey: thank you for your suggestions and help. Not sure what you mean by "adding a *key* to the individual sheets to revert to SUMIF. Additionally I used to find SUMIF to be limited, though more efficient when trying to sum using several criteria. Maybe SUMIFS does that now, though as you mention would not be backward compatible.
To tackle step by step:
Can someone help me with writing a VBA script in EXCEL which is triggered by a single click on a cell in a table, and then getting a pop-up with a list of the following information: a) the row number, b) the column number, c) the value of the cell, and d) the formula in the cell
So the pop-up would be something like:
- Row:10
- Column: M
- Value: 57 EUR
- Formula: "=SUM(('Peter 2010'!$H$6:$H$958=$C10)*('Peter 2010'!$E$6:$E$958=M$6)*('Peter 2010'!$J$6:$J$958))+SUM(('John 2010'!$H$6:$H$1866=$C10)*('John 2010'!$E$6:$E$1866=M$6)*('John 2010'!$J$6:$J$1866))"
Thank you!
You can't pop up in a pivottable, you can drill down & it is more efficient than array formulas and VBA
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Consider A1:C10000 of:
Now consider we want to SUM C where A is "a" and B is "z"a x 67 b x 12 c y 10 d z 26 a y 39 a z 16 b z 94 c x 38 a x 10 b y 80 etc...
Prior to XL2007 we could as you have shown use an Array or SUMPRODUCT equiv.
However these formulae are inefficient... prior to XL2007+ a good alternative is to concatenate fields of interest, eg:=SUMPRODUCT(($A$1:$A$10000="a")*($B$1:$B$10000="z");$C$1:$C$10000)
We can now dispense with inefficient formulae and revert to SUMIF using a concatenated criteriaD1: =$A1&"@"&$B1 copied down to D10000
used in large volume and/or with large ranges and/or in volatile context the gain from the SUMIF approach is likely to prove significant.=SUMIF($D$1:$D$10000;"a@z";$C$1:$C$10000) (obviously the criteria need not be a constant)
SUMIF also offers wildcard functionality so if we wanted to just search for "non-blank@z" then:
a well constructed key offers lots of flexibility and in an efficient manner.=SUMIF($D$1:$D$10000;"?*@z";$C$1:$C$10000)
With Excel as you know Elegance and Efficiency do not always equate to the same and Efficiency is always the more important consideration (IMO)
*also have D functions... but can prove cumbersome depending on configuration
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
@royUK: that is true, when I write a spreadsheet for myself, I use PivotTables. This time the spreadsheet is for my parents, they don't even know what Excel is, so I am trying to make it simple. When they see a number and want to know what is behind it, I would like it to be intuitive and for them to get some details on the number when clicking...
@DonkeyOte: I see what you mean. In my case I guess I could use SUMIFS, though SUMIF is not enough given that I am using more than one criteria. Nevertheless I am actually summing more than one column in my real spreadsheet, which would probably not work with SUMIFS, unless I used a support column and then added them together. Regardless, I think I will use SUMIFS to make it smoother, though need to see the backward compatibility on that with Excel 2003. Thanks for your explanations!
Given all this, I am going back to the step by step approach...first figuring out how to make a pop-up with the information of the cell that triggered the event.
Can anyone help with this first step?
Thanks so far!![]()
Last edited by ssdlfun; 11-05-2010 at 08:53 AM.
I can only guess from the above that you did not follow the example I provided ?
Correct - that holds true for both SUMIF & SUMIFSOriginally Posted by ssdlfun
(unless dimensions of criteria tests match the summation range - which they won't here).
If you need backwards compatibility then you can not use SUMIFS.Originally Posted by ssdlfun
See the Selection Change event, however, I can only reiterate that this is not the method you should be pursuing... given you are seemingly intent on this approach I confess I bow out at this point.Originally Posted by ssdlfun
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I did follow your examples (I think I did it right...maybe I am not doing it right). With SUMPRODUCT you are right, though wtih SUMIF it does not seem like I can do more than one criteria (??)
The only thing I can say is what I said above again:See the Selection Change event, however, I can only reiterate that this is not the method you should be pursuing... given you are seemingly intent on this approach I confess I bow out at this point.
This time the spreadsheet is for my parents, they don't even know what Excel is, so I am trying to make it simple. When they see a number and want to know what is behind it, I would like it to be intuitive and for them to get some details on the number when clicking...
If you have another suggestion on how to provide someone with detailed information who does not know Excel at all, or almost computers, I am happy to hear it. The type of detailed information is not that deep, it should only be a summary of what values were added to come up with the final number.
Thanks so far! Really!
I can't see your spreadsheet because I don't have Excel 2007. If you are set on doing things your way against the suggestions of others, then so be it. Try using an amendment of the code below to have a validation popup whenever a cell is clicked. It contains the row, column, amount, and formula within that cell.
Note: As it is setup, the code is only going to work for column A, but you can change that as necessary. This code should be input into the worksheet code for the applicable sheet. Let me know if it helps at all.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim rw As String Dim col As String Dim val As Currency Dim fmu As String Dim inpt As String If Target.Column = 1 And Target.Count = 1 Then With Target rw = CStr(.Row) col = CStr(.Column) val = CCur(.Value) fmu = CStr(.Formula) inpt = rw & Chr(10) & col & Chr(10) & val & Chr(10) & fmu End With With Target.Validation .Delete .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _ :=xlBetween .IgnoreBlank = True .InCellDropdown = True .InputTitle = "Information" .ErrorTitle = "" .InputMessage = inpt .ErrorMessage = "" .ShowInput = True .ShowError = True End With End If End Sub
It seems given your prior point re: summation dimension that this is a moot discussion but multiple criteria is the purpose of the concatenation, no ?
the above uses two criteria - a & z the two being merged into a single condition by virtue of concatenated key column (D at source)=SUMIF($D$1:$D$10000;"a@z";$C$1:$C$10000)
If you mean you want multiple "multiple" criteria - ie "a@z" and "b@z" then
=SUM(SUMIF($D$1:$D$10000;{"a"\"b"}&"@z";$C$1:$C$10000)) confirmed with Enter -- use of inline array perhaps not best advice here.. -- I am also guessing at Spanish delimiter being \I believe I've offered some pointers on all aspects.Originally Posted by ssdlfun
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Perhaps you could use this UDF.
A cell holding the formula
=ThreeFormulas(A1+B2+C3, "Car fare:"&A1&CHAR(13) &"Ticket:"&B2&CHAR(13) &"Dinner:"&C3)
will display the sum in the first argument. Selecting that cell will show a validation input message determined by the second argument. (and the third, if it exists)
Function ThreeFormulas(Formula1 As Variant, Optional Formula2 As Variant, Optional Formula3 As Variant) As Variant Dim formulaSnip As String, val2 As String, val3 As String Application.Volatile With Application.Caller formulaSnip = Mid(.Formula, 16) With .Validation .Delete .Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop _ , Formula1:="=True", Operator:=xlBetween .ShowInput = True If Not IsMissing(Formula3) Then .InputTitle = CStr(Evaluate("CHOOSE(2," & formulaSnip)) .InputMessage = CStr(Evaluate("CHOOSE(3," & formulaSnip)) ElseIf Not IsMissing(Formula2) Then .InputMessage = CStr(Evaluate("CHOOSE(2," & formulaSnip)) End If End With End With ThreeFormulas = Evaluate("CHOOSE(1," & formulaSnip) End Function
Last edited by mikerickson; 11-05-2010 at 10:19 AM.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
Hello BigBas!
Wow, this looks really great. Exactly what I wanted. I just need to play around with it a little bit and then add some iteration code to it, but for now THANK YOU!
Cheers!
p.s. I will work on this and get back with the next step in a few. Thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks