• Msgbox based on contents of a range

    Author
    Topic
    #479886

    Hi

    Can anyone help please I would like to code a Msgbox to appear based on the contents in a range.
    i.e. if any cell in the range I3 to I34 contains the text “Duplicate Booking” then Msgbox appears saying not available.

    Thanks in advance

    I am using Excel 2010

    Viewing 4 reply threads
    Author
    Replies
    • #1305591

      Braddy,

      Try this, worked for me. :cheers:

      Code:
      Sub RangeMsg()
        
        Dim rngFound As Range
        With Range(“I3:I34”)
          Set rngFound = .Find(“Duplicate Booking”)
          If Not rngFound Is Nothing Then MsgBox “Not Available”
        End With
      End Sub
      
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1305596

      Hi RetiredGeek

      Thank you for the Code

      Could I impose on you to explain exactly where to place this code, Many Thanks.

      Regards

      Braddy

      • #1305599

        Could I impose on you to explain exactly where to place this code, Many Thanks.

        Braddy,

        That depends on how you want it to be called. As it stands it is a standalone module and could be called from any other code in your VBA project. The code itself, w/o the Sub & End Sub lines could be incorporated directly into any existing code you have. You could also have it fire off of a WorkSheet change event it you want it to run any time one of the Cells in the range change value.

        Let me know. :cheers:

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

    • #1305603

      Hi

      I tried it in the sheetchange event but it runs every time the sheet changes whether I3 to I34 contains Duplicate Booking or not.

      Regards

      Braddy

    • #1305701

      You can test for an intersection first:

      Code:
      Private Sub Worksheet_Change(ByVal Target As Range)
         Dim rngFound          As Excel.Range
         If Not Intersect(Target, Range("I3:I34")) Is Nothing Then
            With Range("I3:I34")
               Set rngFound = .Find("Duplicate Booking")
               If Not rngFound Is Nothing Then MsgBox "Not Available"
            End With
         End If
      End Sub
      
    • #1305801

      Hi Rory

      I think I have a problem elsewhere because I cannot get your code to work. I will have to do some checking.

      Many Thanks for the code.

      Regards
      Braddy

    Viewing 4 reply threads
    Reply To: Reply #1305591 in Msgbox based on contents of a range

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel