Results 1 to 7 of 7

Thread: Conditional Appearance of msgbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    May 2020
    Posts
    66
    Rep Power
    5

    Conditional Appearance of msgbox

    Case:
    There are 3 cells- "P20", "U20" and "Z20".
    "Z20" contains the formula =IF(P20<U20,"??","")

    I've this VBA in the sheet

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim xCell As Range, Rg As Range
        On Error Resume Next
        Set Rg = Application.Intersect(Target, Range("Z20"))
        If Not Rg Is Nothing Then
            For Each xCell In Rg
                If xCell.Value = "??" Then
                    MsgBox "Entry Error"
                    Exit Sub
                End If
            Next
        End If
    End Sub
    
    Private Sub Worksheet_selectionChange(ByVal Target As Range)
        Dim xCell As Range, Rg As Range
        On Error Resume Next
        Set Rg = Application.Intersect(Target, Range("Z20"))
        If Not Rg Is Nothing Then
            For Each xCell In Rg
                If xCell.Value = "??" Then
                    MsgBox "Entry Error"
                    Exit Sub
                End If
            Next
        End If
    End Sub

    Problem:
    Msgbox appears only when I select the Cell "Z20" (If it contains "??")


    My requirement:
    1. Msgbox should appear immidiately after appearance of "??" in the cell "Z20"
    That is, whenever a value is entered in the cell "P20" or "U20", and P20<U20 (as the formula set in cell Z20), immidiately the msgbox should appear.
    2. Also, the msgbox should appear when the cell Z20 contains "??" and the cell Z20 is selected. (It is working currently)

    Please find the attachment below for more clarity.

    Many Thanks!
    Attached Files Attached Files

Similar Threads

  1. Msgbox notification with paasword by vba macro
    By fixer in forum Excel Help
    Replies: 8
    Last Post: 07-07-2020, 01:21 PM
  2. Conditional formatting
    By mahmoud-lee in forum Excel Help
    Replies: 9
    Last Post: 05-30-2013, 03:00 PM
  3. Conditional Formatting using formula.
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-18-2013, 11:33 PM
  4. Conditional Formatting - If/And Formula
    By Katrina in forum Excel Help
    Replies: 4
    Last Post: 11-23-2012, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •