+ Reply to Thread
Results 1 to 7 of 7

Msgbox to display multiple results if they occur

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Msgbox to display multiple results if they occur

    Hi all,

    Hope someone can help me with this. I have a msgbox problem that I cant solve on my own. In my set of data i would like a code that checks if there in column Z is the word "Missing" and if so displays the values from the cells on the same row but columns H and I in a msgbox. If there are any "Missing" in col Z i need to stop running the code after a click on a OK-Button. The prompt for the msgbox is "Something seems to be missing, check out:"

    For each row that there is "Missing" i col Z i would like one row in the msgbox with the values from cells H and I in the same row. The number of rows can vary. The columns are from A - AA.

    I have uploaded a workbook, maybe it gets a little bit clearer what i mean if you look in that.


    Masun
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Msgbox to display multiple results if they occur

    Hi Masun,

    Let us know how this goes:

    Option Explicit
    Sub Macro1()
    
        'Written by Trebor76
        'Visit my website www.excelguru.net.au
        
        'Display all entries from Col's H and I where there is the text 'Missing' in Col Z of the same Row.
    
        Dim rngCell As Range
        Dim strMyMessage As String
        
        Application.ScreenUpdating = False
        
        For Each rngCell In Range("Z2:Z" & Range("Z" & Rows.Count).End(xlUp).Row)
            If InStr(rngCell, "Missing") > 0 Then
                If strMyMessage = "" Then
                    strMyMessage = "Something wrong with:" & vbNewLine & Range("H" & rngCell.Row) & " " & Range("I" & rngCell.Row)
                Else
                    strMyMessage = strMyMessage & vbNewLine & Range("H" & rngCell.Row) & " " & Range("I" & rngCell.Row)
                End If
            End If
        Next rngCell
        
        If strMyMessage = "" Then
            MsgBox "No instances of ""Missing"" were found in Col. Z.", vbInformation, "Excel Guru"
        Else
            MsgBox strMyMessage, vbExclamation, "Excel Guru"
        End If
        
        Application.ScreenUpdating = True
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Msgbox to display multiple results if they occur

    Hi Trebor,

    Thanks for your help! Seems to be working fine!

    /Masun

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Msgbox to display multiple results if they occur

    You're welcome

    If you could please mark the thread as solved it would be appreciated.

    Regards,

    Robert

  5. #5
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Msgbox to display multiple results if they occur

    Trebor, thanks for your help but unfortunately i did not test the code enough and i would really appreciate som further help from you (or anyone else for that matter).

    I use the code you provided as a part of another code. If there are any "Missings" in col Z the msgbox appears just like i want to but when I click the ok buttun the code continues to run, i would like the msgbox to appear and when clicking the ok button i want to stop running the code, some sort of end sub if you understand what i mean. If there are no missings i dont need a msgbox to appear, then the code can keep on running like Forrest Gump...

    /Masun

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Msgbox to display multiple results if they occur

    Hi Masun,

    Replace these lines...

    If strMyMessage = "" Then
            MsgBox "No instances of ""Missing"" were found in Col. Z.", vbInformation, "Excel Guru"
        Else
            MsgBox strMyMessage, vbExclamation, "Excel Guru"
        End If
    ...with this:

    If strMyMessage <> "" Then
            MsgBox strMyMessage, vbExclamation, "Excel Guru"
            Exit Sub
        End If
    HTH

    Robert

  7. #7
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Msgbox to display multiple results if they occur

    Trebor,

    Perfect! Thank you!! Once again i will mark this thread as solved...

    /Masun

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count if, display results in msgbox
    By j9070749 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-24-2012, 12:22 AM
  2. Display multiple search results in a row
    By Alicita in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 01-24-2011, 10:45 AM
  3. How to display values that occur multiple times
    By fnb4321 in forum Excel General
    Replies: 2
    Last Post: 07-03-2009, 06:14 PM
  4. How to display multiple results from a list?
    By oliccm in forum Excel General
    Replies: 8
    Last Post: 01-26-2009, 02:23 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1