+ Reply to Thread
Results 1 to 14 of 14

Creating inputbox code to fix errors while macro running? (With example)

  1. #1
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Creating inputbox code to fix errors while macro running? (With example)

    Hi all,

    Example below.

    Question: Is it possible to set up a userform that would fix problems if the macro runs into an error?

    In the example I have Countries in my DataTable and I have Countries in the LookUpTable, with a colour assigned to the Countries, and I have a code, which loops through each row in the DataTable, and tells me if the Country is "RED" or "Not RED". The only problem is, that in the DataTable, I have blanks, and some users input city names instead of countries, or abbreviations.

    So would it be possible, to fix it while my macro is running with a userform? It hopefully would be able to do 2 things:

    First example: Macro runs into Spain, which is not in my LookUpTable, and I would like the userform to pop up saying:

    "Spain is not in the LookUpTable, do you want to change the cell in the DataTable?" Corrected country name: (Inputbox here) YES / NO

    If the user inputs something in the Inputbox and clicks yes, then change the cell value to the inputbox value, and resume the macro checking if the country name that has just been put in is "RED" or "Not RED"

    If the user clicks no, then stop the macro, so the user can go back to the LookUpTable, and add the country that caused the error, to the LookUpTable.


    For the blanks the same userform should pop up and the user can decide to input a country name, or just write "BLANK" which is also in the LookUpTable.

    This is a VBA project, and I need to solve it with VBA, so please don't waste your own time solving the problem with formulas!

    Could someone help me with this please?

    Question posted on Mr.Excel Message Board as well link: https://www.mrexcel.com/forum/excel-...ml#post5230254
    Attached Files Attached Files
    Last edited by LIL2606; 02-23-2019 at 08:20 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Fixing errors with userform while macro running? (With example)

    There is no Userform here. Please Amend your Title.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Fixing errors with userform while macro running? (With example)

    I have a code that may solve your problem, but as requested please amend your title... as mentioned this does not have a userform involved.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating userform to fix errors while macro running? (With example)

    I was asking to help create a userform, so for me the original title made sense too.. but I hope the new one makes my question more understandable.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Creating userform to fix errors while macro running? (With example)

    Ok, given your description, the title does work, I just didn't understand you were asking for a form (apologies)... but my suggestion is not to use a userform since we can keep it much simpler. If you truly DO want a userform we can make the necessary changes. In the meantime, see if this code will satisfy your needs?

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating userform to fix errors while macro running? (With example)

    This is EXACTLY what I wanted thank you so much!! I'm a bit new to VBA I thought this is a userform?

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Creating userform to fix errors while macro running? (With example)

    No it is just some message boxes and input boxes, but not a userform

    Glad I could help, if your issue is resolved please remember to mark the thread as solved? Thanks!

  8. #8
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating inputbox code to fix errors while macro running? (With example)

    Little issue, when we press cancel from the inputbox, it still inputs BLANK into the cell, would it be possible, that if we press cancel it would not change what is in the cell, it would just exit sub?

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Creating inputbox code to fix errors while macro running? (With example)

    I'll look at it soon... My assumption was if they answer yes to the first question, then we should update the cell no matter what.

  10. #10
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating inputbox code to fix errors while macro running? (With example)

    Thats fine too, but then can the cancel button not be there? Just cause it's confusing..

  11. #11
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating inputbox code to fix errors while macro running? (With example)

    I managed to write a working version, with a userform at the end, but I bumped into another issue. I am marking this thread solved, and posting my other problem in a new one.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Creating inputbox code to fix errors while macro running? (With example)

    Sorry for the delay, this would take care of the Cancel button or the X at the top of the box being used. If the user did that program stops as if they had said No to the question about updating. If they just left it blank and hit ok then "BLANK" would be entered. I gather you don't need it anymore, but thought I'd post just in case.

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    08-29-2017
    Location
    London England
    MS-Off Ver
    2016
    Posts
    194

    Re: Creating inputbox code to fix errors while macro running? (With example)

    Thank you for answering this anyway. I actually tried this as well, because someone suggested it on Mr.Excel Message board, but with this, when I hit cancel it input "False" into my cell instead of just not changing it. Maybe I wrote it wrong somehow, but it didn't work for me..

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Creating inputbox code to fix errors while macro running? (With example)

    The issue with "FALSE" was probably because you need to make sure to handle the case where StrPtr(new_country) is 0. Either make new_country = vbNullString or exit the sub as I did in my code. That said, if you have already solved it in another way, then great, and this probably doesn't matter anymore. Thanks for the reply and feedback though

+ 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. Replies: 1
    Last Post: 01-30-2018, 11:46 PM
  2. [SOLVED] Optimizing already available macro by fixing run time errors
    By anshul1719 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2016, 08:03 AM
  3. Data Validation Errors and Running a Macro
    By excelhelp2469 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2015, 11:07 AM
  4. [SOLVED] Avoid Errors when running macro buttons simultaneously
    By KassimVBA7 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-15-2015, 10:26 AM
  5. [SOLVED] Need help fixing a formula, currently returning errors and dont know how to fix it
    By 33CDonnelly in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-15-2013, 04:17 PM
  6. Macro creates new sheet but when running it errors.
    By MIchaelb1100 in forum Excel Programming / VBA / Macros
    Replies: 33
    Last Post: 06-07-2013, 08:51 AM
  7. help fixing my macro from running multiple times
    By MurseBry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2010, 02:17 AM

Tags for this Thread

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