bowling score help

golf401

New Member
Joined
May 4, 2003
Messages
40
I've seen a few bowling formulas within mr. excel but nothing in code. so i tried it and the only problem i have is when a player strikes.....then the code should add the next two balls thrown..... it works if the next two are strikes but not if there is no 'mark'. So basically its not adding the second ball. The code looks right unless I'm just missing something. heres the code....
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'********** FRAME 1 **********
'strike 1 & 2
If [b3] + [d3] = 20 Then
    [score1] = [b3] + [d3] + [f3]
        Else
            'strike 1
            If [b3] = 10 And [d3] <> 10 Then
                [score1] = [b3] + [d3] + [e3]
            End If
                'spare
                If [b3] + [c3] = 10 Then
                    [score1] = [b3] + [c3] + [d3]
                        Else
                        'no marks
                            [score1] = [b3] + [c3]
                                End If
End If
'******** END FRAME 1 ********

'********** FRAME 2 **********
'strike 2 & 3
If [d3] + [f3] = 20 Then
    [score2] = [score1] + [d3] + [f3] + [h3]
        Else
            'strike 2
            If [d3] = 10 And [f3] <> 10 Then
                [score2] = [score1] + [d3] + [f3] + [g3]
            End If
                'spare
                If [d3] + [e3] = 10 Then
                    [score2] = [score1] + [d3] + [e3] + [f3]
                        Else
                        'no marks
                        [score2] = [score1] + [d3] + [e3]
                            End If
End If
'******** END FRAME 2 ********
'********** FRAME 3 **********
'strike 3 & 4
If [f3] + [h3] = 20 Then
    [score3] = [score2] + [f3] + [h3] + [j3]
        Else
            'strike 3
            If [f3] = 10 And [h3] <> 10 Then
                [score3] = [score2] + [f3] + [h3] + [i3]
            End If
                'spare
                If [f3] + [g3] = 10 Then
                    [score3] = [score2] + [f3] + [g3] + [h3]
                        Else
                        'no marks
                        [score3] = [score2] + [f3] + [g3]
                            End If
End If
'******** END FRAME 3 ********
'********** FRAME 4 **********
'strike 4 & 5
If [h3] + [j3] = 20 Then
    [score4] = [score3] + [h3] + [j3] + [l3]
        Else
            'strike 2
            If [h3] = 10 And [j3] <> 10 Then
                [score4] = [score3] + [h3] + [j3] + [k3]
            End If
                'spare
                If [h3] + [i3] = 10 Then
                    [score4] = [score3] + [h3] + [i3] + [j3]
                        Else
                        'no marks
                        [score4] = [score3] + [h3] + [i3]
                            End If
End If
'******** END FRAME 4 ********
'********** FRAME 5 **********
'strike 5 & 6
If [j3] + [l3] = 20 Then
    [score5] = [score4] + [j3] + [l3] + [n3]
        Else
            'strike 5
            If [j3] = 10 And [l3] <> 10 Then
                [score5] = [score4] + [j3] + [l3] + [m3]
            End If
                'spare
                If [j3] + [k3] = 10 Then
                    [score5] = [score4] + [j3] + [k3] + [l3]
                        Else
                        'no marks
                        [score5] = [score4] + [j3] + [k3]
                            End If
End If
'******** END FRAME 5 ********
'********** FRAME 6 **********
'strike 6 & 7
If [l3] + [n3] = 20 Then
    [score6] = [score5] + [l3] + [n3] + [p3]
        Else
            'strike 6
            If [l3] = 10 And [n3] <> 10 Then
                [score6] = [score5] + [l3] + [n3] + [o3]
            Else
                'spare
                If [l3] + [m3] = 10 Then
                    [score6] = [score5] + [l3] + [m3] + [n3]
                    Else
                        'no marks
                            [score6] = [score5] + [l3] + [m3]
End If
End If
End If




'******** END FRAME 6 ********
'********** FRAME 7 **********
'strike 7 & 8
If [n3] + [p3] = 20 Then
    [score7] = [score6] + [n3] + [p3] + [r3]
        Else
            'strike 7
            If [n3] = 10 And [p3] <> 10 Then
                [score7] = [score6] + [n3] + [p3] + [q3]
            Else
                'spare
                If [n3] + [o3] = 10 Then
                    [score7] = [score6] + [n3] + [o3] + [p3]
                    Else
                        'no marks
                            [score7] = [score6] + [n3] + [o3]
                            End If
                            End If
                            End If
'******** END FRAME 7 ********
'********** FRAME 8 **********
'strike 8 & 9
If [p3] + [r3] = 20 Then
    [score8] = [score7] + [p3] + [r3] + [t3]
        Else
            'strike 8
            If [p3] = 10 And [r3] <> 10 Then
                [score8] = [score7] + [p3] + [r3] + [s3]
            Else
                'spare
                If [p3] + [q3] = 10 Then
                    [score8] = [score7] + [p3] + [q3] + [r3]
                    Else
                        'no marks
                            [score8] = [score7] + [p3] + [q3]
                            End If
                            End If
                            End If
'******** END FRAME 8 ********
'********** FRAME 9 **********
'strike 9 & 10
If [r3] + [t3] = 20 Then
    [score9] = [score8] + [r3] + [t3] + [u3]
        Else
            'strike 9
            If [r3] = 10 And [t3] <> 10 Then
                [score9] = [score8] + [r3] + [s3] + [t3]
            Else
                'spare
                If [r3] + [s3] = 10 Then
                    [score9] = [score8] + [r3] + [s3] + [t3]
                    Else
                        'no marks
                            [score9] = [score8] + [r3] + [s3]
                            End If
                            End If
                            End If
'******** END FRAME 9 ********
'********** FRAME 9 **********
'strike ball one two & three
If [t3] + [u3] + [v3] = 30 Then
    [score10] = [score9] + [t3] + [u3] + [v3]
        Else
            'strike ball one and spare two/three
            If [t3] = 10 And [u3] <> 10 Then
                If [u3] + [v3] = 10 Then
                [score10] = [score9] + [t3] + [u3] + [v3]
                Else
                [score10] = [score9] + [t3] + [u3]
                End If
                End If
                End If
'******** END FRAME 10 ********
End Sub

thanks in advance
 
Ian Mac said:
All,

Juan yes the score should be 47.

Sixth Sense, your code is correct until the last frame.
I haven't tested very much but:

9 - Spare across the board should be 199 not 190.
Book2
ABCDEFGHIJKLMNOP
112345
2Ian9s199s389s579s769s95
Sheet1
Book2
QRSTUVWXYZAAABACADAEAF
1678910
29s1149s1339s1529s1719s9190
Sheet1


BTW Still very nice work.

Regards,

Mac,
Check the checker given by golf401. its says 190!
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Was just going to post and apologies for my error, and say that Sixth Sense's answer was actually correct and very good

All that, and BTW Sensey! it's Ian or Ian Mac
 
Upvote 0
Ian Mac said:
Was just going to post and apologies for my error, and say that Sixth Sense's answer was actually correct and very good

All that, and BTW Sensey! it's Ian or Ian Mac

Sorry for that Ian.
My setmate here in office is MAC. I suppose you got
the same nicknames!

(y)
 
Upvote 0
Hi!
golf!
Here i am again!
if you insist this set up, then try again!
Bowling.xls
ABCDEFGHIJKLMNOPQRSTUV
1PlayersFrameFrameFrameFrameFrameFrameFrameFrameFrameFrame
212345678910
31XXxxxx0xxxXXX
4306090120150180210240270300
5
629S9S9S9S9S9S9S9S9S9S9
71938577695114133152171190
8
Bowling2



The code!

This goes to the standard module!!!<font face=Courier New><SPAN style="color:#00007F">Type</SPAN> BallStatus1
    Strike<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Boolean</SPAN>
    Spare<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Boolean</SPAN>
    Score<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Type</SPAN><SPAN style="color:#00007F">Type</SPAN> Oneframe1
    Thisround(0 To 1)<SPAN style="color:#00007F">As</SPAN> BallStatus1<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Type</SPAN><SPAN style="color:#00007F">Sub</SPAN> Scoring2(<SPAN style="color:#00007F">ByVal</SPAN> PlayerNumber<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN>)<SPAN style="color:#00007F">Dim</SPAN> MyScore(9)<SPAN style="color:#00007F">As</SPAN> Oneframe1<SPAN style="color:#00007F">Dim</SPAN> MyScorePerFrame(9)<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN><SPAN style="color:#00007F">Dim</SPAN> colx<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN><SPAN style="color:#00007F">Dim</SPAN> Bunos<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN>
colx = 2
Rowx = 3 * PlayerNumber<SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(MyScore)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(MyScore)<SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">Case</SPAN> UCase(Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value)
    <SPAN style="color:#00007F">Case</SPAN> "X"
        MyScore(I).Thisround(0).Strike =<SPAN style="color:#00007F">True</SPAN>
        MyScore(I).Thisround(0).Spare =<SPAN style="color:#00007F">False</SPAN>
        MyScore(I).Thisround(0).Score = 10
        MyScore(I).Thisround(1).Strike =<SPAN style="color:#00007F">False</SPAN>
        MyScore(I).Thisround(1).Spare =<SPAN style="color:#00007F">False</SPAN>
        MyScore(I).Thisround(1).Score = 0
    <SPAN style="color:#00007F">Case</SPAN><SPAN style="color:#00007F">Else</SPAN>
        MyScore(I).Thisround(0).Score = Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">If</SPAN> MyScore(I).Thisround(0).Strike =<SPAN style="color:#00007F">False</SPAN><SPAN style="color:#00007F">Then</SPAN>
    TMP = UCase(Range(Cells(Rowx, colx + 1), Cells(Rowx, colx + 1)).Value)
    <SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">Case</SPAN> TMP
        <SPAN style="color:#00007F">Case</SPAN> "S"
            MyScore(I).Thisround(1).Strike =<SPAN style="color:#00007F">False</SPAN>
            MyScore(I).Thisround(1).Spare =<SPAN style="color:#00007F">True</SPAN>
            MyScore(I).Thisround(1).Score = 10 - MyScore(I).Thisround(0).Score
        <SPAN style="color:#00007F">Case</SPAN><SPAN style="color:#00007F">Else</SPAN>
            MyScore(I).Thisround(1).Strike =<SPAN style="color:#00007F">False</SPAN>
            MyScore(I).Thisround(1).Spare =<SPAN style="color:#00007F">False</SPAN>
            MyScore(I).Thisround(1).Score = Range(Cells(Rowx, colx + 1), Cells(Rowx, colx + 1)).Value
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
colx = colx + 2<SPAN style="color:#00007F">Next</SPAN> I
TMP = Range(Cells(Rowx, colx - 1), Cells(Rowx, colx - 1)).Value<SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">Case</SPAN> UCase(TMP)
Case "X"
    MyScore(UBound(MyScore)).Thisround(1).Score = 10
    MyScore(UBound(MyScore)).Thisround(1).Strike =<SPAN style="color:#00007F">True</SPAN>
    MyScore(UBound(MyScore)).Thisround(1).Spare =<SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">If</SPAN> U<SPAN style="color:#00007F">Case</SPAN>(Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value) = "X"<SPAN style="color:#00007F">Then</SPAN>
        Bunos = 10
    <SPAN style="color:#00007F">Else</SPAN>
        Bunos = Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
Case "S"
    MyScore(UBound(MyScore)).Thisround(1).Score = 10 - MyScore(UBound(MyScore)).Thisround(0).Score
    MyScore(UBound(MyScore)).Thisround(1).Strike =<SPAN style="color:#00007F">False</SPAN>
    MyScore(UBound(MyScore)).Thisround(1).Spare =<SPAN style="color:#00007F">True</SPAN>
    <SPAN style="color:#00007F">If</SPAN> U<SPAN style="color:#00007F">Case</SPAN>(Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value) = "X"<SPAN style="color:#00007F">Then</SPAN>
        Bunos = 10
    <SPAN style="color:#00007F">Else</SPAN>
        Bunos = Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
Case<SPAN style="color:#00007F">Else</SPAN>
    MyScore(UBound(MyScore)).Thisround(1).Score = Range(Cells(Rowx, colx - 1), Cells(Rowx, colx - 1)).Value
    MyScore(UBound(MyScore)).Thisround(1).Strike =<SPAN style="color:#00007F">False</SPAN>
    MyScore(UBound(MyScore)).Thisround(1).Spare =<SPAN style="color:#00007F">False</SPAN>
    Bunos = 0<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Select</SPAN><SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(MyScore)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(MyScore) - 1
            <SPAN style="color:#00007F">If</SPAN> MyScore(I).Thisround(0).Strike =<SPAN style="color:#00007F">True</SPAN><SPAN style="color:#00007F">Then</SPAN>
                <SPAN style="color:#00007F">If</SPAN> MyScore(I + 1).Thisround(0).Strike<SPAN style="color:#00007F">Then</SPAN>
                    <SPAN style="color:#00007F">If</SPAN> I =<SPAN style="color:#00007F">UBound</SPAN>(MyScore) - 1<SPAN style="color:#00007F">Then</SPAN>
                        MyScorePerFrame(I) = MyScore(I).Thisround(0).Score + MyScore(I + 1).Thisround(0).Score + MyScore(I + 1).Thisround(1).Score
                    <SPAN style="color:#00007F">Else</SPAN>
                        MyScorePerFrame(I) = MyScore(I).Thisround(0).Score + MyScore(I + 1).Thisround(0).Score + MyScore(I + 2).Thisround(0).Score
                    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
                <SPAN style="color:#00007F">Else</SPAN>
                    MyScorePerFrame(I) = MyScore(I).Thisround(0).Score + MyScore(I + 1).Thisround(0).Score + MyScore(I + 1).Thisround(1).Score
                <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
                            
            <SPAN style="color:#00007F">ElseIf</SPAN> MyScore(I).Thisround(1).Spare =<SPAN style="color:#00007F">True</SPAN><SPAN style="color:#00007F">Then</SPAN>
                MyScorePerFrame(I) = MyScore(I).Thisround(0).Score + MyScore(I).Thisround(1).Score + MyScore(I + 1).Thisround(0).Score
            <SPAN style="color:#00007F">ElseIf</SPAN> (MyScore(I).Thisround(0).Strike =<SPAN style="color:#00007F">False</SPAN>) And (MyScore(I).Thisround(1).Spare =<SPAN style="color:#00007F">False</SPAN>)<SPAN style="color:#00007F">Then</SPAN>
                MyScorePerFrame(I) = MyScore(I).Thisround(0).Score + MyScore(I).Thisround(1).Score
            <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Next</SPAN> I
MyScorePerFrame(UBound(MyScore)) = MyScore(UBound(MyScore)).Thisround(0).Score + MyScore(<SPAN style="color:#00007F">UBound</SPAN>(MyScore)).Thisround(1).Score + Bunos
TMP = 0<SPAN style="color:#007F00">'output score</SPAN>
colx = 2
Rowx = PlayerNumber * 3 + 1<SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(MyScore)<SPAN style="color:#00007F">To</SPAN> UBound(MyScore) - 1
    TMP = MyScorePerFrame(I) + TMP
    Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value = TMP
    colx = colx + 2<SPAN style="color:#00007F">Next</SPAN> I
  Range(Cells(Rowx, colx), Cells(Rowx, colx)).Value = TMP + MyScorePerFrame(UBound(MyScore))<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>

And this goes the sheet module!!!<font face=Courier New><SPAN style="color:#00007F">Private</SPAN><SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target<SPAN style="color:#00007F">As</SPAN> Range)<SPAN style="color:#00007F">On</SPAN><SPAN style="color:#00007F">Error</SPAN><SPAN style="color:#00007F">GoTo</SPAN> en
Application.EnableEvents =<SPAN style="color:#00007F">False</SPAN>
Application.ScreenUpdating =<SPAN style="color:#00007F">False</SPAN><SPAN style="color:#00007F">Set</SPAN> isect = Application.Intersect(Target, Range("b2:V11"))
    <SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> isect<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN>
        PlayerNumber = ActiveCell.Row / 3
        <SPAN style="color:#00007F">Call</SPAN> Scoring2(PlayerNumber)
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
en:<SPAN style="color:#00007F">If</SPAN> Err.Number<> 0<SPAN style="color:#00007F">Then</SPAN>
    MsgBox "Error occurs" & Chr(13) & Err.Number<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
Application.ScreenUpdating =<SPAN style="color:#00007F">True</SPAN>
Application.EnableEvents =<SPAN style="color:#00007F">True</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>


Note:
Just tested very quickly. but i think it looks fine!
 
Upvote 0
NateO said:
Jay Petrulis said:
The author has an AOL username, hrlngrv, and is my favorite Excel guru. If you figure out who he is from his moniker, you will know who I mean and why I say he's my favorite. :LOL:
Hmmm, who could we be talking about here? :ROFLMAO:

Sorry, off-topic somewhat, but had to guess. :)

Was it that easy? :wink: A perfect reference to the legend that is Harlan Grove.

Harlan is as good as Aladin (possibly better) at native excel formulas -- that *is* saying a helluva lot. He is a supreme coder in VBA -- easily on par with the best of them. He likely knows mathematics/statistics/probability at the level of the best of the Excel math whizzes (Dave Braden, Jerrry L. Lewis, et al). He knows all the spreadsheet options (1-2-3, quattro pro, Gnumeric, Star/OpenOffice, etc.). He knows other languages (and participates in the awk groups just as he does in the Excel ones).

But the best of all is his personality. If you read the Harlan Chronicles, you get free entertainment. Unless, of course, you are on the receiving end of his wrath. He is called the newsgroup curmudgeon for a really good reason. Ponsy Nob. is good, too, but I'll take the Harlan barbs at this stage of their careers.

The only technical weakness is that he may not be up to the level of a Jon Peltier, Tushar Mehta, or an Andy Pope at graphing. He may be, but he hasn't jumped in any charting discussions that I have seen.

My first trip every day to the world of Excel is to search google for Harlan Grove as the key terms. Only then do I enter MrExcel.
 
Upvote 0
Not to be rude........... but what part of this topic have anything to do with bragging about someone? I thought this topic was about "bowling", anyways, the file did work well thanks.
 
Upvote 0
Hey Sixth Sense, thank you for taking so much time on this. I tried running this program and i keep getting an error about the type?
"Compile error:
Cannot define a Public user-defined type within an object module"

The scores arent coming up, for some reason I cant figure it out.
thanks in advance!
 
Upvote 0
golf401 said:
Not to be rude........... but what part of this topic have anything to do with bragging about someone? I thought this topic was about "bowling", anyways, the file did work well thanks.
Not at all. The brief dialogue was assigning credit, and then some, to the relevant file that you reference as working well. :p
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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