+ Reply to Thread
Results 1 to 16 of 16

Macro Runs fine in debug but not from ComboBox

  1. #1
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Macro Runs fine in debug but not from ComboBox

    I have a workbook that contains 9 worksheets. Four of the worksheets have the same row lables in column B and must always be the same. Three of the worksheets are fed from the 4th sheet so that the integrity of the lables is maintained.

    The user can change the lable value to meet their needs and they can insert or delete rows (within limits) as they see fit.

    The attached macro "Sub Delete_Row_All_Sheets()" works fine when I run it from Debug (F8).

    However, when I run it from Forms.ComboBox the macro returns to the "y = Application.InputBox("Enter The Row Number You Wish To Delete", _" screen. If I select cancel, the results I anticipated occur but I don't want the user to have to assume this will happen.

    Why does the macro return to this screen when executed from the ComboBox but not when executed from Debug?

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    I am using Excel 2007 on worksheets in .xls compatability mode.

    This is my first posting. Your "How To Videos" appear to be not working so I could not watch them to see proper protocol. Hope I didn't mess up too bad.

    Thanks for your help.

    John
    Last edited by jaslake; 02-25-2009 at 10:27 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs fine in debug but not from ComboBox

    An example workbook would be useful. I think you need to use a Combobox from the Controls ToolBox.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro Runs fine in debug but not from ComboBox

    Welcome to the forum.

    It's going to run the InputBox line no matter how you enter it, right?
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    I am using a ComboBox from the controls toolbox (AxtiveX). I can attach a sample workbook. I will need to copy my wookbook and delete all of the personal information. This will take a little time.

    Thanks...J

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    SHG...I'm not sure I understand your question, however, when I run the macro, the user is asked to enter the row number they wish to delete. They can enter any number greater than 7 (column headers, etc. are in the first seven rows). Also, there are certain other rows that are reserved (I have entered X's in column A of these rows and the macro looks to see in column A is empty; if it's not empty, the macro tells them they cannot delete this row.

    Now, this works fine in debug; however, from the ComboBox, the Input box reappears and asks for a row number (it should not reappear, the macro should complete).

    After the Input box reappears, if I enter a 0, the macro completes; if I select cancel, the macro completes; if I enter a legitimate row number, I get the message "Delete Method of Range Class Failed". However, I should not even be looping back to the Input box. Therein lies the problem. Why am I getting a second view of the input box when I run the macro from ComboBox when I don't get a second view in debug?

    Does this answer your question?

    J

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    I have attached a test file as requested. Please ignore the #REF references. I've deleted several worksheets to reduce the size of the file and they have no relevance to the issue.

    Thanks....J
    Attached Files Attached Files

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs fine in debug but not from ComboBox

    The change event attempts to run a sub called combobox1, which doesn't exist

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs fine in debug but not from ComboBox

    Try this
    Please Login or Register  to view this content.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    royUK...I've replaced my Private Sub ComboBox1_Change() coding with that you suggested (I did this in a copy of the file I submitted earlier). I still get the same results....a second Input Box.

    Take a look at the file I provided and see if you can duplicate my problem. Run the macro (macro 16) in debug (F8) and it will complete without a second pass at the Input Box. Running from ComboBox results in a second pass at the Input Box.

    Let me know if you cannot duplicate the issue.

    Thanks...J

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs fine in debug but not from ComboBox

    I can't see how the combobox can call the macro with your code. I have amended your coding
    Please Login or Register  to view this content.

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    royUK...I replaced my macro coding with the code you suggested. I ran the insert macro from the ComboBox to give me a few extra rows to play with.

    I then ran macro16 (the delete macro) from the ComboBox. It appeared to run the first time. I didn't get a second input box prompt. I ran it again (to delete one of the new extra rows I inserted).

    This time, I did get another input box prompt. Is something not clearing to cause the input box prompt to come up again?

    Thanks...J

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro Runs fine in debug but not from ComboBox

    TRy this
    Please Login or Register  to view this content.

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    royUK...yes, I had previously tried to set y=0; had no effect. The interesting thing is that the insert macro works fine. It does not give me the second Input Box.

    I had previously cloned the insert macro for the delete macro (with obvious changes and deletions). However, the problem we are discussing arose so I rewrote the macro but still have the issue. Have you been able to duplicate the problem?

    Thanks...J

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    royUK...this is my current code. Still have same problem. Looping back to InputBox.

    Please Login or Register  to view this content.

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Macro Runs fine in debug but not from ComboBox

    Add a private variable to determine whether the combo box is already doing something. When you delete row from the AnnualBudget sheet it causes the Change event to fire again.

    Code in AnnualBudget sheet object
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Runs fine in debug but not from ComboBox

    That did the trick. Thank you very much. I spent 3 frustrating days trying to get the macro to behave.

    Your help is greatly appreciated.

    J

+ 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