help with formula

prich01

New Member
Joined
Dec 13, 2016
Messages
6
I would like to create a spreadsheet that would help me automatically manage the required amount of rest for baseball pitchers. The columns of the spreadsheet would be the date and the rows would be the players. The requirements are as follows:

<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
1-25no rest
26-551 day rest
56-752 days rest
76-1193 days rest
1204 days rest

<colgroup><col style="width: 100px"><col width="100"></colgroup><tbody>
</tbody>


So it would look something like this and would automatically determine required rest based upon the number of pitches entered in on any given date.


3/1/17 3/2/17 3/3/17 3/4/17 3/5/17 3/6/17
Smith 120 REST REST REST REST
Lewis 0 27 REST 58 REST REST
Brown 0 40 REST 35 REST
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Welcome to the Board!

Since your data grid contains both hard-coded values you are entering in (number of pitches) and automatically populated values (where REST appears), I think this is going to require VBA to do it, as any cell can only contain either a formula or a hard-coded value (but not both at the same time.

This VBA code is very dependent upon where all the data resides on the sheet. So please provide the details, i.e. What is the first row of data? What are the exact columns your dates are in?
 
Upvote 0
Right-click on the sheet tab name at the bottom of the sheet, select View Code, and enter this code in the resulting VB Editor window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'   Exit if more than one cell updated simultaneously
    If Target.Count > 1 Then Exit Sub

'   Only run if not in the first row or column
    If Target.Row = 1 Or Target.Column = 1 Then Exit Sub
    
    Application.EnableEvents = False
    
    Select Case Target.Value
        Case Is >= 120
            Range(Target.Offset(0, 1), Target.Offset(0, 4)) = "Rest"
        Case Is >= 76
            Range(Target.Offset(0, 1), Target.Offset(0, 3)) = "Rest"
        Case Is >= 56
            Range(Target.Offset(0, 1), Target.Offset(0, 2)) = "Rest"
        Case Is >= 16
            Target.Offset(0, 1) = "Rest"
        Case Is >= 1
            'Do nothing
        Case Else
            MsgBox "Invalid entry!"
    End Select

    Application.EnableEvents = True
    
End Sub
This should do what you want automatically. Just enter some values in and see what happens.
 
Upvote 0
Wow that is awesome. One more question. Is there a way to get fancy and have the "REST" cells pop up with a red background?
 
Upvote 0
I figured out the colors. If I type in 120 it automatically produces 4 consecutive days of rest. If I delete the 120 the other 4 cells don't automatically go back to blank. Is there a way for it to do that or is that asking too much?
 
Upvote 0
Just as an alternative, here is a formula solution that could work.

ABCDEFGHIJKL
13/13/20173/14/20173/15/20173/16/20173/17/20173/18/20173/19/20173/20/20173/21/20173/22/2017
2Martin0
3Smith0
4Lewis
0
5Thompson0
6Houston0
7Gates0
8R. Phillips0
9D. Phillips0
10Cole0
11Myers0
12Koinig0
13Davis0
14DeMars0
15Chesson0
16Ott0
17
18PitchesRest Days
1900
20251
21552
22753
231204

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet11

Worksheet Formulas
CellFormula
C2=IF(COLUMN(C2)>VLOOKUP(LOOKUP(2,1/ISNUMBER($B2:B2),$B2:B2),$A$19:$B$23,2)+LOOKUP(2,1/ISNUMBER($B2:B2),COLUMN($B2:B2)),"","REST")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



At the start of the season, build your spreadsheet as shown, and put the C2 formula in as shown. Note the column of 0s in B, and note how I adjusted the Pitches/Rest Days table.

Now, whenever you have a number to enter, just put it in, overwriting the formula. It could look something like:
ABCDEFGHIJKL
13/13/20173/14/20173/15/20173/16/20173/17/20173/18/20173/19/20173/20/20173/21/20173/22/2017
2Martin02457RESTREST77RESTRESTREST
3Smith0
4Lewis
056RESTREST
5Thompson033REST27REST
6Houston0
7Gates0
8R. Phillips088RESTRESTREST21
9D. Phillips0
10Cole0
11Myers0
12Koinig0
13Davis0
14DeMars0
15Chesson0
16Ott0
17
18PitchesRest Days
1900
20251
21552
22753
231204

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet11



To get the red highlighting, whether you use Joe's method or mine, just use Conditional Formatting. Select columns B:ZZ (or whatever your last column is), click Conditional Formatting > Highlight Cells Rules > Text that Contains > type in REST and click OK.
 
Upvote 0
I did just as you show and I get the following: A N/A in every cell and Did not find value '2' in LOOKUP evaluation.
 
Upvote 0
nevermind, it does work in excel. Since I may be sharing with a large number of coaches, is there a way for this to work in google sheets?
 
Upvote 0
I'm sorry, I don't know enough about Google Sheets to say. You might try wrapping ArrayFormula() around it. And you do need to copy the formula to the entire range C2:L16.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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