Msgbox prompted by change in value of certain cells

Beware Wet Paint

New Member
Joined
Jul 9, 2013
Messages
34
Hi guys I'm having a little trouble getting a macro to work in the way i intend. I want a msgbox to pop up when the value of certain cells in a column are greater than one. I've found a number of codes that *Almost* work but they seem to be based on a range e.g A1:A5... what I'd be after is for it to only concern specific cells within that range e.g A2 and A3. Any advice oh gurus of the spreadsheets? Massive thanks in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is one example.

Code:
  Select Case Target.Address
    Case "$A$2", "$A$3", "$B$2", "$B$3"
        If Target.Value > 1 Then
            MsgBox "The value in cell " & Target.Address & " is greater than 1"
        End If
    End Select
Add the above code to the Worksheet_Change event for the worksheet you want to do this on. E.g.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Select Case Target.Address
    Case "$A$2", "$A$3", "$B$2", "$B$3"
        If Target.Value > 1 Then
            MsgBox "The value in cell " & Target.Address & " is greater than 1"
        End If
    End Select
End Sub
 
Upvote 0
Place this code in the worksheet_change event

Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A2:A3")) Is Nothing Then Exit Sub
    If Target.Value > 1 Then
        MsgBox "Target is greater than 1"
    End If
End Sub
 
Upvote 0
Would there be anyway to adapt this to work on cells where the value is calculated by formula? E.g A2=B2+C2? Both codes work perfectly when the content of the range is just pure numerical input but don't when the range is calculated by formula
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngCheck As Range, R As Range


    With Me
        Set rngCheck = Union(.Range("$A$2"), .Range("$A$3"), .Range("$B$2"), .Range("$B$3"))
    End With


    For Each R In rngCheck
            If R.Value > 1 Then
                MsgBox "The value in cell " & R.Address & " is greater than 1"
            End If
   Next R
End Sub

Though if you use it for too many cells, the msgbox popups could get to be annoying.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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