+ Reply to Thread
Results 1 to 7 of 7

Exit Row search code from MsgBox

  1. #1
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Exit Row search code from MsgBox

    Hi

    I've a code that searches down a column and picks out rows where values meeting certain criteria are anomalies. Each anomaly brings up a Message box that identifies the problem. The message Box has yes/no buttons to allow the user to either exit the sub and fix the issue or continue with the check of the column.

    Running through the code "manually" using F8 the
    Please Login or Register  to view this content.
    is seen by the code, but clicking on "No" doesn't exit the sub.

    If I separate the code after "Then" and put the Exit Sub on the next line down, the code throws up "Next with no For" when it reaches the line "Next cll".

    If I move the
    Please Login or Register  to view this content.
    outside of the "If cll.Value" lines of code it gets ignored on a manual run-through.

    What do I need to do to get the MsgBox "No" button to stop the code and the "Yes" button to let the code continue please?

    Here's the code
    Please Login or Register  to view this content.
    Example spreadsheet with code is attached.

    Many thanks

    Frankie
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Exit Row search code from MsgBox

    Hi, Frankie,

    there is no relation between the outcome of the MessageBox and response so the code canīt end.

    From what I know the code should not be placed begind a sheet but inside a standard module:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Exit Row search code from MsgBox

    Hi Frankie,

    itīs not a big deal but you should consider a Select Case against your Ifs. Every cell value will be checked with all Ifs no matter what value is shown while the Select Case will pass the cases and if a case is true the rest of them will be omitted. By checking for the contents to be equal to 2 first the code may look like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,305

    Re: Exit Row search code from MsgBox

    declare - Dim intResponse as vbMsgBoxResult not as Integer

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,305

    Re: Exit Row search code from MsgBox

    change your LastRow search it does not appear to find anything
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Exit Row search code from MsgBox

    Thanks for sorting my code out HaHoBe. Much appreciated.
    Even more appreciated is the improved code you've supplied!!
    Thanks!

  7. #7
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    309

    Re: Exit Row search code from MsgBox

    Hoi Torachan

    LastRow is used to find a place down a column that is within the overall much larger column length. I probably shouldn't have used the wording "LastRow" as that bit of code equals a variable number on (another) sheet in the actual spreadsheet I'm working with. The next line of code ("RangeEnd") then adds the column ident to the number. So if LastRow = 63 then RangeEnd would = BZ63, giving a range (rng) of BZ5:BZ63.

    I'm sure there's a better way of doing it but I was quite proud that I'd made it work!!

    But thanks for the input. Much appreciated.

    Frankie

+ 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] MSGBOX with structured data - OK / EXIT
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2013, 01:23 PM
  2. [SOLVED] If duplicate is found in column B, delete Row, if not, msgbox and exit
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-18-2013, 11:34 AM
  3. [SOLVED] MsgBox Exit Sub
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-19-2012, 01:00 PM
  4. MsgBox vbYesNo and Exit Sub
    By Monkeyboyz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-30-2010, 12:46 PM
  5. IF Statements + MsgBox and Exit Excel without saving
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2009, 09:13 PM
  6. how to popup msgbox once exit ?
    By vumian in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2006, 10:04 AM
  7. If pressed no to msgbox, then exit sub
    By Hari in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2005, 11:06 AM

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