Worksheet change not working

winstela

New Member
Joined
Feb 24, 2019
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
Good Evening All

Can anyone help me with below worksheet change event as its not working. I want to be able to check when a cell is change if the row total in the range is greater than 60 then show msgbox and then clear the contents.

so if the cell that was changed was P11 and the sum total for O11 to V11 was then greater than 60 clear contents for range O11 to V11

Thanks for looking
W

VBA Code:
If Not Intersect(Target, Range("O9:V24")) Is Nothing Then
    For Each celV In Target
        myRowV = celV.Row
  
        Application.EnableEvents = False
    
    If Application.WorksheetFunction.Sum(.Range("o" & myRowV & ":V" & myRowV)) > 60 Then
MsgBox "you cannot exceed 60 mins"
Range("o" & myRowV & ":V" & myRowV).ClearContents
      
        Application.EnableEvents = True
        End If
    Next celV
End If
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi there. You have a surplus period before the Range, also you will be disabkling events and not reenabling unless the message came out. I have removed the period and moved the enableevents line: try this mod:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("O9:V24")) Is Nothing Then
    For Each celV In Target
        myRowV = celV.Row
  
        Application.EnableEvents = False
    
    If Application.WorksheetFunction.Sum(Range("o" & myRowV & ":V" & myRowV)) > 60 Then
MsgBox "you cannot exceed 60 mins"
Range("o" & myRowV & ":V" & myRowV).ClearContents
      
        End If
        Application.EnableEvents = True

    Next celV
End If
End Sub
 
Upvote 0
Solution
Thanks for your quick reply,
I think that is what happened. The enable events was not set back to true .
Once I saved the file and re-opened it works perfectly
I have an enable events true on opening the workbook

Thank you again
W
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,174
Latest member
chandan4057

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