Excel formula to count when value changes?

bbarge

New Member
Joined
Nov 4, 2014
Messages
5
Hi all,

I have an Excel conundrum I can't seem to crack.

In Column A I have a long list of counties in a spreadsheet, and each of those counties is a member of a larger group of counties that pertain to a particular funding request to our organization. In column B is the total funding amount in that request--i.e. if an organization received $3,000 and claims to serve counties Smith, Robeson, Macon, and Duplin, the spreadsheet looks like this:

A1 Smith B1 3000
A2 Robeson B2 3000
A3 Macon B3 3000
A4 Duplin B4 3000
.. and the list goes on with counties from other requests, for about 1200 total row entries.

I'm trying to set up a function that allows the total amount for each particular request group (e.g., 3000) to be divided up by the number of cells *up until* the B value changes. So, if the next B value is 6500, for example, the formula would only count A1-A4 in the denominator. This would theoretically allow me to drag the formula across the entire column, as opposed to manually changing the range every time there's a new grouping of counties. (The entries have already been ordered so that no two groupings of counties from a same-value request (i.e. two 10,000 value requests) are adjacent to each other).

I've been using COUNT formulas, such as B1/(COUNT(B1:B4)) to get the values I need, but this strategy requires me to change the range manually. I have not been able to construct a COUNT formula that can account for an unknown range based on a value *change* rather than occurrence. I would appreciate any help you could provide!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Obviously you can have duplicated Amounts ($3,000; $3,000).. hummm
 
Last edited:
Upvote 0
Right, but that's ok. As long as those amounts are the same, I want the formula to apply to those fields, because they represent the same proposal. It's when that number changes--signifying a new request--that I'd want the formula to automatically adjust as well. You're right that, within the entire worksheet, there may be multiple sets of counties from 3000-sized requests. That's the trick.
 
Upvote 0
See if this is ok


A
B
C
1
Counties​
Funding​
Amount/County​
2
County1​
3000​
750​
3
County2​
3000​
750​
4
County3​
3000​
750​
5
County4​
3000​
750​
6
County5​
6000​
1200​
7
County6​
6000​
1200​
8
County7​
6000​
1200​
9
County8​
6000​
1200​
10
County9​
6000​
1200​
11
County10​
1500​
1500​
12
County11​
3000​
3000​
13
County12​
1200​
600​
14
County13​
1200​
600​
15
County14​
10000​
1000​
16
County15​
10000​
1000​
17
County16​
10000​
1000​
18
County17​
10000​
1000​
19
County18​
10000​
1000​
20
County19​
10000​
1000​
21
County20​
10000​
1000​
22
County21​
10000​
1000​
23
County22​
10000​
1000​
24
County23​
10000​
1000​
25
County24​
900​
450​
26
County25​
900​
450​

Formula in C2 copied down
=IF(B2=B1,C1,B2/COUNT(B2:INDEX(B2:$B$10000,MATCH(TRUE,INDEX(B3:$B$10000<>B2,0),0))))

Hope this helps

M.
 
Upvote 0
Someone else may come up with a formula, but I opted to write a macro... So with your spreadsheet looking like so...

Run this Macro (see below -- paste into a Standard module)



Excel 2012
ABC
1CountyJoint GrantShare Amts
2Smith3,000.00
3Robeson3,000.00
4Macon3,000.00
5Duplin3,000.00
6ABC6,600.00
7DDD6,600.00
8FFF6,600.00
9Montgomery3,000.00
10Smith3,000.00
11Rankin3,000.00
Sheet1


Code:
Sub Foo()
LR = Range("A" & Rows.Count).End(xlUp).Row
Cnt = 0
Set Rng = Range("A2:A" & LR)
    For Each C In Rng
        If C.Offset(, 1) = C.Offset(1, 1) Then
        Cnt = Cnt + 1
        Else
        Cnt = Cnt + 1
        C.Offset(-Cnt + 1, 2).Resize(Cnt, 1).Formula = "=(B" & C.Row - Cnt + 1 & "/" & Cnt & ")"
        Cnt = 0
        End If
    Next C
End Sub
 
Upvote 0
Many, many thanks to you both! I have tried the formula and it works perfectly. The macro is a great option too.

You have no idea how much time you have saved me and my coworkers.
 
Upvote 0

Forum statistics

Threads
1,215,394
Messages
6,124,683
Members
449,180
Latest member
kfhw720

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