summing the highest digits in a string of numbers

dwrowe001

Board Regular
Joined
Mar 12, 2017
Messages
53
Office Version
  1. 2016
Platform
  1. Windows
Hi,
despite what the title says, it isn't as easy as just that...
What I'm doing is tracking the number of times a number is skipped, incrementing 1 each skip, then when the number is drawn a "0" is entered into the string, and the process starts again. so it looks something like this:
12340123456780123456789101112130120.... each zero is when the number is drawn.. then the next drawn if the number isn't picked a 1 is entered, adding 1 for each time it is skipped. I have the numbers going down from B1 down to B262.

I have this formula copied down from B16 to B300:
IF('Number Counts'!A3="","",IF(COUNTIF('Number Counts'!B3,1),0,B13+1))

I would like to stream line the process, instead of having the long string of numbers from B16 down to B262, I would like to have the current skip count appearing in 1 Cell.

Also, I would like to add the last digit before the number hits.. In the below string string example:
12340123456780123456789101112130120, I would like to add the numbers 4, 8, 13, 2... there would be more numbers of course, this is shortened for simplicity.

Hope these make sense...
thanks
Dave
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I'm not exactly sure
- what you have
- what you want
- where you want it

Any chance you could show a few different examples of your data, layout and expected results and explain again in relation to that?
My signature block below has a link for suggestions of how you can do that.
 
Upvote 0
I don't see a feasible way to do this with standard worksheet formulas, but you could try the user-defined functions. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formulas as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Function CountSkips(s As String) As Long
  Dim stmp As String
  Dim j As Long

  j = 1
  Do
    If s Like stmp & j & "*" Then
      stmp = stmp & j
      j = j + 1
    Else
      CountSkips = CountSkips + 1
      stmp = stmp & 0
      j = 1
    End If
 Loop Until Len(stmp) >= Len(s)
End Function


Function SumHigh(s As String) As Long
  Dim stmp As String
  Dim j As Long

  j = 1
  Do
    If s Like stmp & j & "*" Then
      stmp = stmp & j
      j = j + 1
    Else
      SumHigh = SumHigh + j - 1
      stmp = stmp & 0
      j = 1
    End If
 Loop Until Len(stmp) >= Len(s)
End Function


Excel 2016 (Windows) 32 bit
ABC
1SkipsSum
212340123456780123456789101112130120427
3101230123012340120513
41234012314
Sheet1
Cell Formulas
RangeFormula
B2=CountSkips(A2)
C2=SumHigh(A2)



Since you only gave one example, I'm not sure if all strings will end with a zero or whether examples like row 4 above are possible?
If that is possible, what results do you want for each of Skips and Sum?
 
Last edited:
Upvote 0
Peter,
I apologize for not being more clear and specific of what I need help with. I’ll try to explain better..
I am tracking lotto picks. Lotto has 5 balls, with a number pool of 60. This specific issue I need help with is dealing with how many times a given number is skipped.
I have all picks listed on tab named Working 1:[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Date
[/TD]
[TD]ball 1
[/TD]
[TD]ball 2
[/TD]
[TD]ball 3
[/TD]
[TD]ball 4
[/TD]
[TD]ball 5
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]5/4/2015
[/TD]
[TD]3
[/TD]
[TD]5
[/TD]
[TD]7
[/TD]
[TD]9
[/TD]
[TD]11
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]5/7/2015
[/TD]
[TD]1
[/TD]
[TD]6
[/TD]
[TD]11
[/TD]
[TD]22
[/TD]
[TD]60
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]5/11/2015
[/TD]
[TD]5
[/TD]
[TD]8
[/TD]
[TD]15
[/TD]
[TD]20
[/TD]
[TD]44
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]5/13/2015
[/TD]
[TD]13
[/TD]
[TD]19
[/TD]
[TD]33
[/TD]
[TD]45
[/TD]
[TD]59
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]5/17/2015
[/TD]
[TD]1
[/TD]
[TD]10
[/TD]
[TD]12
[/TD]
[TD]33
[/TD]
[TD]44
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
In my Original post I was tracking the number 1.. in the above example, 1 is drawn 2 times for ball 1. my list starts tracking the lotto on 5/4, with the #3 , then on 5/7 #1 is picked for ball 1, so there would be 1 skip before ball 1 is picked on 5/7. then #1 isn't picked again till 5/17, there are 2 skips between 5/7 and 5/17. I am trying to come up with a formula that would add the number of skips between draws.. in my original post I said I was using this formula:
IF('Number Counts'!A3="","",IF(COUNTIF('Number Counts'!B3,1),0,B13+1)) to get the below results:
12340123456780123456789101112130120. The zeros represent when the number 1 is drawn. the numbers between the zeros are the number of skips. I would like to try to add the last digits before the zeros, which represent the number of skips before the number is drawn.. so that would be 4,8,13,2 = 27. I'm adding new picks weekly to the list on Working 1.

Thank you
Dave
 
Upvote 0
Hmm, that certainly does seem a bit different to what was posted to start with. :)


I have all picks listed on tab named Working 1:[TABLE="class: grid, width: 200"]
[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Date
[/TD]
[TD]ball 1
[/TD]
[TD]ball 2
[/TD]
[TD]ball 3
[/TD]
[TD]ball 4
[/TD]
[TD]ball 5
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]5/4/2015
[/TD]
[TD]3
[/TD]
[TD]5
[/TD]
[TD]7
[/TD]
[TD]9
[/TD]
[TD]11
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]5/7/2015
[/TD]
[TD]1
[/TD]
[TD]6
[/TD]
[TD]11
[/TD]
[TD]22
[/TD]
[TD]60
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]5/11/2015
[/TD]
[TD]5
[/TD]
[TD]8
[/TD]
[TD]15
[/TD]
[TD]20
[/TD]
[TD]44
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]5/13/2015
[/TD]
[TD]13
[/TD]
[TD]19
[/TD]
[TD]33
[/TD]
[TD]45
[/TD]
[TD]59
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]5/17/2015
[/TD]
[TD]1
[/TD]
[TD]10
[/TD]
[TD]12
[/TD]
[TD]33
[/TD]
[TD]44
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[/TABLE]
.. number 1.. in the above example, 1 is drawn 2 times for ball 1. my list starts tracking the lotto on 5/4, with the #3 , then on 5/7 #1 is picked for ball 1, so there would be 1 skip before ball 1 is picked on 5/7. then #1 isn't picked again till 5/17, there are 2 skips between 5/7 and 5/17. I am trying to come up with a formula that would add the number of skips between draws..
So presumably the result for the above simple example is 3 (1+2)??

Suppose that red "1" had been anything else, would the expected result be 1 or would it be 4, or something else?
If the answer to that is 4, then try this formula. Note that I have set up the 'ball 1' to replicate what I think matches your earlier "12340123456780..." example

Excel Workbook
BCDEFGHIJ
1ball 1ball 2ball 3ball 4ball 5No.BallSkips
21413018251127
34552114918
41958522451
5542222652
6151261620
74028273837
8171827715
9517145448
103833474821
114136511047
125357346038
1342853216
14285942921
15149492858
163020561337
172215245014
18178583244
194530105929
203532305447
214449415125
225357324560
2314911140
241254511729
253057124422
262437255145
27342214826
284341292721
29135476031
30541462324
314623212313
32142521146
33
Working 1


An alternative formula that should do the same job would be:
Code:
=COUNT(INDEX(B2:F40,0,I2))-COUNTIF(INDEX(B2:F40,0,I2),H2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,785
Messages
6,174,537
Members
452,571
Latest member
MarExcelTips

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