It should work but it doesn't?

KeeranB

New Member
Joined
Aug 9, 2018
Messages
6
Hi. I'm pretty new to VBA coding, and have been given the task of adding a warning popup box when a certain cell (merged into others so this one cell occupies the space of 6), exceeds another cell's Value (which also occupies 6 cells as 1).

The first cell shows a weekly labour budget that is calculated from others dotted around the sheet with regards to target labour of 26%, divided from a weekly sales forecast = budget (cell S9). The other cell which is the cell in question is a running total of spend in £ value (cell L9). Whilst the sheet is populated with Start & Finish times manually by the store manager (on same sheet), in real time the value calculates the total wage for the day for each staff member listed as they go, x hourly rate = total wage, which is in a hidden column, then L9 is a simple =SUM to show total labour spend of those smaller values.

What I would like to happen is when L9 exceeds S9, a message box jumps out and says, "Labour Budget exceeded. Please reconfigure." I would also like the code to undo the last input just before the message box was triggered due to L9 being greater than S9.

I found some existing code listed in another thread (didn't have the undo last entry bit though), attempted to incorporate that on the VBA code screen for the sheet with a few reference changes, but it does absolutely nothing. It's as if the code isn't even there!

When I Save, and click the green 'play' button to run the code, it asks me to create a Macro. Wtf ??? Am I missing something here, coz I have no clue what's happening.

I would post my work for you to see but I don't have it with me at the moment. I'm sure you smartypants out there have the answer that makes it so obvious. Any help would be massively appreciated.
 
not exactly what you need but on the right track i think:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


With Application
  .EnableEvents = False
  .ScreenUpdating = False
  
If Target.Cells.Count = 1 Then
    If Left(Target.Address, 3) = "$J$" And Target.Row > 13 And Target.Row < 27 And Target <> "" Then


    
        If Target.Offset(0, 2).Value > Target.Offset(0, 9).Value Then
        MsgBox ("Exceeded Limit")
        Target.ClearContents
        End If
    End If


End If


    
  .EnableEvents = True
  .ScreenUpdating = True
End With




End Sub

This event triggers for range ("J14:J26") when the value in L exceeds value in S on same row
Displays error message then clears the entered data

Not sure how you would revert the cell value
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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