+ Reply to Thread
Results 1 to 9 of 9

VBA to display message box if a value in a column is found then stop the macro

  1. #1
    Registered User
    Join Date
    01-09-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    4

    VBA to display message box if a value in a column is found then stop the macro

    Hi

    I have a sheet which I use a macro to save as a csv file.

    What I would like to do is search column H and if #N/A is found (from vlookup) then I want to display a message box to say #N/A found and then stop the macro from continuing.

    I know that an IF statement needs to be used and I know how to find the value, but cannot work out where to start on how to get the message box when found and stop the macro from running.
    I only need to find the value once even though there may be multiple instances.

    Many thanks in advance for taking a look and any suggestions.

    Dan

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: VBA to display message box if a value in a column is found then stop the macro

    After you find a N/A write
    Please Login or Register  to view this content.
    it will stop macro at the time and continue after you click OK.
    If you want to exit sub then write
    Please Login or Register  to view this content.
    after Msgbox

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to display message box if a value in a column is found then stop the macro

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-09-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA to display message box if a value in a column is found then stop the macro

    thanks both.

    John, how can I limit the amount of rows it searches through (to 14001 only) and for the loop be stopped if #N/A is not found?

    Thanks

    Dan

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: VBA to display message box if a value in a column is found then stop the macro

    try
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to display message box if a value in a column is found then stop the macro

    Quote Originally Posted by dantgk1 View Post
    thanks both.

    John, how can I limit the amount of rows it searches through (to 14001 only) and for the loop be stopped if #N/A is not found?

    Thanks

    Dan
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-09-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA to display message box if a value in a column is found then stop the macro

    thank you both for your time in helping me with this.

    Dan

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA to display message box if a value in a column is found then stop the macro

    You're welcome Dan. Glad you got you're problem solved.

  9. #9
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: VBA to display message box if a value in a column is found then stop the macro

    Hello Dan,

    Is it possible for you to attach the excel file with the solution?? That will be a great help for us.

    Thanl you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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