URGENT: How To Pop Up Message Box If Cell Greater Or Less Than A Specific Value In Excel?

Emanuel1980

New Member
Joined
Jul 21, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm using the below code to pop a message box whenever the value of cells in column "J" is greater than 8. The target value which is 8 in this case is in Cell A1.

The issue i'm having here is i get the pop up for any value that is entered whcih should not be the case. It must pop up only when the value is greater "8"

PLEASE HELP

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
Dim rngJ As Range, rngA As Range
xA = "A1"
Set rngJ = Application.Intersect(Target.EntireRow, Range("J1").EntireColumn)
Set rngA = Application.Intersect(Target.EntireRow, Range("A1").EntireColumn)
If rngJ.Value > rngA.Value Then
MsgBox Prompt:="The hours entered is greater than your scheduled working hours, please enter less than or equal to 8 hours! THANK YOU", Title:="Infovision Social"
Target.Value = ""
End If
End If
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You don't need VB code to do this. You can use Data Validation in the Data Tools under the Data tab.
Highlight the column and select Data Validation.

Settings:
Allow = Whole Number
Data = Less than
MAX= 8

Error Alert tab
Check the box to Show error alert after invalid data is entered.
Style: Stop, Warning or INformation
Title = STOP
Error Message = You are over 8 hours!

Give it a try and see if you like that.
 
Upvote 0
Sorry - MAX = 9 then you can enter 8 for hours.
Thank you for your response.

I tried that earlier and it wouldn't work. Hence i took the VBA route.
1626912817461.png
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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