Consulting

Results 1 to 6 of 6

Thread: Pop-up Message Box when certain values are inputted in Column A

  1. #1

    Pop-up Message Box when certain values are inputted in Column A

    Everytime the values 1002, 1004, and 1005 are inputted in column A, I want the message to pop up "Reminder to indicate color". Below is the code that I have right now in the worksheet. As you can see this works when the value 1002 is inputted but when I tried to make it - If Cell.Value = "1002" Or "1004", the code doesn't work. The message pops up regardless of what the change is. How can I make the message pop up only on the values that I want? Thank you in advance!


    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
      Dim Cell As Range
      If Not Intersect(Target, Columns("A")) Is Nothing Then
        For Each Cell In Intersect(Target, Columns("A"))
          If Cell.Value = "1002" Then MsgBox "Remember to indicate fur label color - red or blue."
        Next
      End If
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    If Cell.Value = "1002" Or Cell.Value = "1004"

    Another way

    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rCell As Range ' try not to use VBA or Excel keywords
    
    
        If Intersect(Target, Columns("A")) Is Nothing Then Exit Sub
        
        For Each rCell In Intersect(Target, Columns("A"))
            Select Case rCell.Value
                Case "1002", "1004"
                    MsgBox "Remember to indicate fur label color - red or blue."
            End Select
        Next
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,872
    Since the loop is to cater for multiple cells in column A being changed at once, as in a copy paste or an entry into multiple cells by holding the Ctrl key while entering data, one can avoid the messsage popping up multiple times by adding Exit For directly after the MsgBox line in Paul's suggestion.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Thanks, Paul! It worked! Additional question though. Is it possible to check if the value of the cell belongs to a list (for example C1:C20) instead of explicitly indicating the values in the code ("1002", "1004")?

    Thanks for the tip, p45cal.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    This is the I habitually do something like. Probably better ways


    Not tested

    Option Explicit
    
    
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rCell As Range ' try not to use VBA or Excel keywords
        Dim n As Long
    
    
        If Intersect(Target, Columns("A")) Is Nothing Then Exit Sub
        
        For Each rCell In Intersect(Target, Columns("A")).Cells
            n = 0
            On Error Resume Next
            n = Application.WorksheetFunction.Match(rCell.Value, Worksheets("Sheet2").Range("C1:C20"), 0)
            On Error GoTo 0
            
            If n > 0 Then
                MsgBox "Remember to indicate fur label color - red or blue. -- " & rCell.Address
            End If
        Next
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Thanks, Paul! It worked!

Tags for this Thread

Posting Permissions

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