Average not changing more than a certain number

Iswearimnotdumb

New Member
Joined
Mar 20, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I'm working on a spreadsheet for my dad and I'm at a complete loss.

When a points score is entered, it automatically updates the Quota. I need a something so the quota does not go down more than 2 points.

We currently have a code on the sheet so when a new number is entered into the points column, it shifts the data into the "1" column and shifts the previous column 1 through 8 over to the right.

Current code is:

Private Sub Worksheet_Change(ByVal Target As Range) 'Excel VBA with more cells in the range.
'
If Not Intersect(Target, Range("B2:B55")) Is Nothing Then
Application.EnableEvents = False
'
Range("E" & Target.Row & ":M" & Target.Row).Cut Range("E" & Target.Row & ":M" & Target.Row).Cells(1).Offset(0, 1)
Range("E" & Target.Row) = Range("B" & Target.Row)
'
Application.EnableEvents = True
End If
End Sub

Any help would be greatly appreciated!!

WCC Dogfight_FORMULAS editing current.xlsm
ABCDEFGHIJKLMNO
1PlayersPointsNet +/-Quota12345678910Total
2Allen, Frankie2018191922232119231918201
3Allman, Willie2827301931272730322828279
Sheet1
Cell Formulas
RangeFormula
D2:D3D2=AVERAGE(INDEX($E:$E,ROW()):INDEX($N:$N,ROW()))
O2:O3O2=SUM(INDEX($E:$E,ROW()):INDEX($N:$N,ROW()))
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You could detect the large quota change with something like this.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range) 'Excel VBA with more cells in the range.
    '
    Dim LastQuota As Double, VA As Variant
    
    If Not Intersect(Target, Range("B2:B55")) Is Nothing And Target.Cells.Count = 1 Then
        LastQuota = Target.Offset(0, 2).Value
        VA = Target.Offset(0, 3).Resize(1, 10).Value
        
        Application.EnableEvents = False
        '
        Range("E" & Target.Row & ":M" & Target.Row).Cut Range("E" & Target.Row & ":M" & Target.Row).Cells(1).Offset(0, 1)
        Range("E" & Target.Row) = Range("B" & Target.Row)
        '
        Application.EnableEvents = True
        
        If LastQuota - Target.Offset(0, 2).Value > 2 Then
            Select Case MsgBox("New quota (" & Target.Offset(0, 2).Value & ") is less than previous quota (" & LastQuota & ") by more than 2. " & vbCrLf & vbCrLf _
                    & "Continue?" & vbCrLf _
                    & "('Cancel' to restore old quota)", vbOKCancel + vbQuestion + vbDefaultButton2, Application.Name)
                Case vbCancel
                    Application.EnableEvents = False
                    Target.Offset(0, 3).Resize(1, 10).Value = VA
                    Target.Value = ""
                    Application.EnableEvents = True
            End Select
        End If
    End If
End Sub
 
Upvote 0
I was thinking maybe....?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range) 'Excel VBA with more cells in the range.

If Not Intersect(Target, Range("B2:B55")) Is Nothing Then
Application.EnableEvents = False
Dim r As Integer
Dim OldQuota As Single
Dim NewQuota As Single

r = Target.Row
OldQuota = Range("D" & r)


Range("F" & r & ":N" & r).Value = Range("E" & r & ":M" & r).Value
Range("E" & r) = Range("B" & r)

NewQuota = WorksheetFunction.Average(Range("E" & r & ":N" & r))

Range("D" & r) = WorksheetFunction.Max(NewQuota, OldQuota - 0.2)
'
Application.EnableEvents = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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