+ Reply to Thread
Results 1 to 11 of 11

Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Hello Everyone,

    My issue is pretty much stated in the title of this thread. When I run a macro through a Form Controls button, it skips part of the process. However, when I rerun that same macro by going to the Developer tab in the ribbon and then choosing the macro from the Macros button, it works fine.

    Has anyone ever had this issue, or does anyone know what might cause it?

    In case it helps, here is the code:


    Please Login or Register  to view this content.

    Thanks!

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    I don't know if this will solve your problem but which sheet is
    Please Login or Register  to view this content.
    Supposed to be referencing? if the intention is to be wSheetStart then it should be
    Please Login or Register  to view this content.
    And the same thing goes for all other Ranges.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Remove On Error Resume Next and you might find where the error in the code is.

    It'll probably be where Modred is suggesting, or on a similar line.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Thanks for the suggestions. Taking out the remove error didn't seem to give an answer and changing the code up gave me a run-time error.

    I guess my issue is, is it really the code? If it works completely fine by running it through the Developer tab, how can code be an issue?

    Thanks again.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Removing On Error is not supposed to fix anything, it's supposed to help you find errors, if they are any.

  7. #7
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Okay, attached is a test workbook. To begin, there are 2 tabs - "Instructions" and "AB - CDE". When you click on button 4 on the instructions tab the macro will run and it will spit out 2 sheets named "Sheet##" and "Sheet##" along with 7 sheets that are labeled Monday through Friday. Now if you run the macro via the Developer tab, your results will be a tabs named "January", "February", and then the Monday through Friday tabs.

    Code stays the same, data stays the same. Macro is just run 2 different ways that should produce the same result.

    ButtonIssueMacro.xlsm

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Which sheet is active when you run the code from developer tab?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Try this, I think I've fixed all the referencing and other problems.

    When I run it from the button it creates sheets for January, February and Monday to Sunday.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    228

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    Norie - That worked great! Thank you very much! Do you have any idea why that code worked instead of what I had? All in all, it pretty much looks like the same stuff, only switched around a little...

    Thanks again!

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,620

    Re: Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option

    I basically implemented what Modred had suggested.

    That made sure that everything was being referenced correctly so the code was running on the right ranges in the right worksheets at the right time.

    I also fixed up some little things that weren't really problems but could become problems/irritations.

+ 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