How do you find an average of multiple cells only AFTER values have been entered in ALL of those cells?

sp70

New Member
Joined
Nov 2, 2008
Messages
1
Hello,
I am working on an electronic score sheet for a pool (8-ball) league. My customer wants to perform a calculation of a NEW player's handicap upon completion of the NEW player's first four games. The problem is that for most new players, they have not yet established a handicap, so users of the spreadsheet would not necessarily know what value to enter for a NEW player's handicap until AFTER the NEW player has played his first four games.

So after the completion of the first four games for that NEW player, then the appropriate cell for the new player's handicap would be populated with the average of those four games.

I am attempting to do this in VBA and I have the following code which I've been switching around in an attempt to get it to work:

Code:
        For Each cel In targ.Cells      'Set the Handicap to 9 for Forfeits. Use VLOOKUP formula otherwise.
            If cel = "Forfeit" Then
                cel.EntireRow.Cells(1, 1).Value = 9
                ' Restrict the Handicap value from populating for new players until they've played 4 games.
            ElseIf cel Like "*(NEW)" Then ' Look for the "New" Player value.
               'cel.EntireRow.Cells(1, 1).Value = cel.EntireRow.Cells(1, 8)
                cel.EntireRow.Cells(1, 1).FormulaR1C1 = "=IF(ROUND(IF(COUNT(D[4]:G[4])=4,AVERAGE(D[4]:G[4]),0),0))"
               '"=IF(ROUND(IF(COUNT.Cells(1, 4:1, 7)=4,AVERAGE.Cells(1, 7:1, 7),0),0))"
               
               'cel.EntireRow.Cells(1, 1).FormulaR1C1 = _
               '     "=IF(RC[2]="""","""",IF(COUNTIF(PlayerData,RC[2]),VLOOKUP(RC[2],ValidationLists!C[1]:C[3],3,FALSE),""""))"
            Else  'set the value of the handicap cell to calculate the average of the four games.
                'cel.EntireRow.Cells(1, 1).Value = cel.EntireRow.Cells(1, 8)
                cel.EntireRow.Cells(1, 1).FormulaR1C1 = _
                    "=IF(RC[2]="""","""",IF(COUNTIF(PlayerData,RC[2]),VLOOKUP(RC[2],ValidationLists!C[1]:C[3],3,FALSE),""""))"
            End If
        Next
The 'Forfeit' section above works just fine. As a reference example, a new player would appear in Cell C4 as 'John Smith (NEW)'. Cell A4 would be the handicap. Cell D4:G4 would be the games that would be played, and H4 already does the average calculation as follows:

Code:
=IF(COUNT(D4:G4)=4,AVERAGE(D4:G4),"")
No matter what I try, I cannot get Cell A4 to populate correctly for a NEW player's calculated average. :(

Also, I don't know if my existing lookup value in cell A4 is overwriting or conflicting with the VBA for this particular function:
Code:
=IF(C5="","",IF(COUNTIF(PlayerData,C5),VLOOKUP(C5,ValidationLists!B:D,3,FALSE),""))
Please let me know if this does not make sense. If you need, I can also email you a copy of the workbook I have for you to look at.

Thank you,

Shad
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You can do as someone suggested to me for a problem, and use:

Code:
 With Range(cells you want to check)
                If Application.CountBlank(.Cells) >0 Then 'Counts empty cells 
                Else ' If there are 0 empty cells in the range
                    Logic here
                Endif
End With
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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