Excel: Simplified SUMs with multiple sheets - excel

I am having troubel figuring this one out using names. To start, take this example
Sheet 1 Sheet 2
|
A B | A B
|
Labor 1000 | Labor 200
Material 1000 | Material 200
|
... | ...
|
Labor 500 | Labor 100
Material 500 | Material 100
The Question: I'd like to be able to total the Labor and Material values up for n number of sheets. The default template starts with two (2) sheets but the user may add any number of sheets they would like.
The Problem (as I see it): The user can add as many "special" page specific item pricing lines to the top of the page. Below that, however, every section (the Labor/Material calculations) are uniformly offset.
If anybody could help me out on this one I'd really appreciate it. Thanks in advance!

Here's the meat of it, I'm having trouble with some of the surround, but I'll update
For i = 1 To counts
For Each wkst In ThisWorkbook.Sheets
wkst.Activate
tots(i) = tots(i) + WorksheetFunction.SumIf(Range("A:A"), categories(i), Range("B:B"))
Next
Next
Where categories is an array that holds "Labor","Material", etc.,tots is an array of doubles (or integers if there won't be any dollar amounts), and counts is the number of elements in categories.

Related

Calculate sum of differences between rows but only if the previous cell is bigger than the current one

I started to get a headache around my problem that I cannot figure out for the love of me.
There are unknown amounts of column if that makes any difference, but basically each row needs to be compared to the previous one and ONLY when the previous value is greater, the difference between them gets added to the sum.
So for example I have this table
| A |
--|-----|
1 | 100 |
2 | 90 |
3 | 80 |
4 | 100 |
5 | 70 |
6 | 20 |
7 | 100 |
...
Expected result: 100, derived from ((100-90) + (90-80) + (100-70) + (70-20))
I have spent a whole day browsing every single excel tutorial page and cannot find a single helpful answer. Please help :(
Formula for Cell B2: (pull down through the rows).
=IF(A1>B1;A1-B1;0)+B1
Logic: If previous value is larger than current value, add the difference to the total.
If you want to do it in one formula, a basic way would be two use two ranges offset by one cell:
=SUMPRODUCT((A1:A6-A2:A7)*(A1:A6>A2:A7))
If you wanted to make a bit more dynamic (assuming there are no gaps in the data) you could try
=SUMPRODUCT((A1:INDEX(A:A,COUNT(A:A)-1)-A2:INDEX(A:A,COUNT(A:A)))*(A1:INDEX(A:A,COUNT(A:A)-1)>A2:INDEX(A:A,COUNT(A:A))))
If there are blanks between numbers, this won't work and you would probably need to go back to a simpler pull-down formula

VBA for Excel to insert rows based on text in sequential rows

I receive an Excel report showing number of patients in a center based on the payer type. Column A lists the center name and the payer types. If there are no patients for a particular payer type, that payer is not listed in the list. I would like to run a script to insert a row as a placeholder wherever a payer is not listed. For example, this is the output of the report:
A | B | C
| |
Region A | Date1 | Date2
| |
Center 123 | |
| |
Private | 4 | 6
Medicaid | 60 | 58
Total | 64 | 64
| |
Center 456 | |
| |
Private | 4 | 4
Medicare | 6 | 8
Hospice | 2 | 2
Managed Cr | 8 | 10
Total | 20 | 24
But I need for all payers/total lines to be listed for each center:
Center 123
Private
Medicare
Medicaid
Medicaid Pnd
Veterans
Hospice
Assisted Lv
Managed Cr
Unassigned
Total
Bed Hold
Total with Bed Holds
Can this be done with VBA to, for example, insert a row after "Private" if "Medicare" is not in the next row - and then put "Medicare" in that new row (column A)? Then insert a row after "Medicare" if "Medicaid" is not in the next row - and put "Medicaid" in the new row, and so on down the list. Thank you in advance for any help you can offer.
Quick question. Your title is vbscript, but your tag is excel-vba. No sure if you know they are two different things.
If your looking for a vba solution, also referred to as a macro, here's an idea.
If you are doing this for esthetics, turn the used range into a table, and hide the rows that don't have any values. This can be done without a macro. But here's a quick macro example:
Sub Button1_Click()
Dim objTable As ListObject
Worksheets("Sheet1").Activate
ActiveSheet.UsedRange.Select
Set objTable = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:= _
"<>"
End Sub
If you were looking for a vbscript solution, its similar, but different syntax.
And a note, you can "Record Macros" in excel. This will allow you to perform a task manually, and excel will give you the macro version of the action. It's not perfect, but for stuff like this it will give you a good place to start.
Yes, this can easily be done with VBA. These are the logical steps you need to take:
Go through each row;
for each row;
Check text in column A and text in the cell below;
if no action is required, do nothing and go to the next row;
if an action is required, execute the desired action;
You can update your question with the code you have so far and describe in detail where exactly you are stuck, and I am pretty sure that we will be able to help you. Please google a specific question first before you ask it here.

Using cell value to set price in another cell

I have a spreadsheet with a list of T-shirts and all of their varying sizes from Small to XL. I was just wondering if there is a way to create a formula that will set the price of the shirt in another row. I was messing around with formulas and the only one I could get to sort of work (for only ONE t-shirt size) was the following:
=IF(COUNTIF(K:K,"S"),25)
Is there a way to have multiple statements for the different sizes? Thanks in advance!
I would create a
"reference table" in a separate sheet and then do a vlookup.
So the table would look like below and then just do a vlookup to where all your shirts are at.
Size | Price
XS | 5
S | 10
M | 15
L | 20
XL | 5

In Excel, how would I divide a sum, and have one cell with a different percentage

I am looking to divide a single sum among various participants.
I have 12 people listed in a column, the next column will contain the divided sum amounts. The cell at the top of the sum column (C13) will have an amount input into it ($90.63) and the formula will then divide that amount among the 12 cells under it.
people | share |
| 90.63 |
-------- | --------- |
person01 | =(C13/12) |
...
person12 | =(C13/12) |
That part I got figured out. so if column C cell 13 had an amount of $90.63 entered, the formula in the 12 cells under it would read =SUM(C13/12), each cell with this formula would then contain a divided amount to show each persons share ($7.55) of the entered amount ($90.63).
However, if one of those 12 people were to only get half of this sum amount share, how do I calculate that while giving the remaining people the extra share?
In essence, if person01 would only get =(C13/24) how do i calculate the share of the remaining 11?
people | fair share | actual share
| 90.63 |
-------- | ---------- | ------------
person01 | =(C13/12) | =(C13/24)
...
person12 | =(C13/12) | ?
Referring to my comments "For one person $C$13/24 and for rest 11 =($C$13-($C$13/24))/11 " I have rechecked and the formula proposed earlier gives correct results. Screenshot is appended below. Moreover this solution is based on Excel terminology rather than Maths.
for 1st person = c13/2 and for others =($c$13)/2/11
Place the total in C1 and then run this:
Sub cropier()
Dim V As Double, i As Long
V = Range("C1").Value
i = 2
Do Until V < 0.01
Cells(i, "C").Value = Cells(i, "C").Value + 0.01
V = V - 0.01
If V < 0.01 Then Exit Sub
For i = 3 To 13
Cells(i, "C").Value = Cells(i, "C").Value + 0.02
V = V - 0.02
If V < 0.01 Then Exit Sub
Next i
i = 2
Loop
End Sub
The macro deals out the money one or two pennies at a time until the money is completely distributed.
The person at C2 gets only half the shares of the others.
Let x be the amount that everyone (but one) pays. Let .5x be the amount that one person pays. The sum, .5x + 11x = 90.63. If you let 11.5x = 90.63, then x=7.88087. The first person pays $3.94 and the rest pay $7.88.
You can double check; 3.94 + 11 * (7.88) = 90.63.
(And yes, this is an algebra problem, not an Excel problem. Nevertheless...)
Create a column of shares that each person would have. Place a .5 in the first row and 1 in the rest. (The sum at the bottom is 11.5, in B15.)
Create a column with 90.63 at the top (here, C1). In C3, place the equation =C$1/$B$15*B3, which says to take the 90.63 and divide it by the total number of shares (11.5) and multiply by how many shares this person is assigned.
Besides them adding up to 90.63, please note that the .5 share is exactly half the amount of the rest.
(For the other answers that are dividing by 11 and such: would you please try your solution and see if you are adding up to 90.63 and whether person 1 pays 3.94?)

Total points for each student in Google spreadsheet or excel

I am in the process of creating a Google form, which students will fill out after attending an event. Based on the event they attend, I will be assigning points to them and this form can be submitted through the whole year.
Is there a way to get a total number of points for each students, since they'll be submitting the form multiple times, I need a way to tally up the points for each students
Example spreadsheet goo.gl/1aunYg
Sam | 2
Jon | 2
Mike | 2
Don | 2
Sam | 3
Sam | 1
Jon | 2
Mike | 1
Total for Sam: ???
Total for Jon: ???
Total for Mike: ???
Total for Don: ???
In google spreadsheets, assuming you have the names in Col A and the scores in Col B, you can also try:
=query(A2:B; "select A, sum(B) where A <>'' group by A label sum(B) 'Totals' ")
This should output an array of unique names and the summed scores.
Sort the list on Name (Home>Sort & Filter)
Add a heading for the columns
Apply SubTotals (Data>Subtotal in the Outline group) at each change in Name and using the function Sum.
You can then hide/show individuals using the controls on the LH side.
Google Spreadsheet see SUMIF
In Excel you could do something like ...

Resources