+ Reply to Thread
Results 1 to 4 of 4

excel vba works from VBA but not from button

  1. #1
    Registered User
    Join Date
    03-21-2014
    Location
    NY
    MS-Off Ver
    Excel 2010, 2013
    Posts
    2

    excel vba works from VBA but not from button

    I have this code that loops through and prints the correct pallet headers with correct amounts and information.

    The VBA works fine when executed from the VBA screen, but only prints the first record the correct amount of times.

    Here is my code. I apologize ahead of time this is my first time working with VBA.

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 07-22-2021 at 09:05 PM.

  2. #2
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    18,634

    Re: excel vba works from VBA but not from button

    I'm not clear on what your problem is, based on reading the title and then reading the second line of your post. It only prints the first record the correct amount of times when invoked by a button, but prints all records the correct amount of times if executed from VBA?

    What module is this code in?
    Where is the button?

    One thing that jumps out right away are these unqualified Range references:

    Please Login or Register  to view this content.
    What worksheet do you intend these to refer to?

    If the code is in a worksheet module (like Sheet1), these ranges will refer to that worksheet.
    If the code is in a standard module (like Module1), these ranges will refer to the active worksheet.

    It is generally weak to depend on what sheet is active for references, unless you have a macro that is designed to be called from different sheets.

    I do not know what sheet you actually want them to refer to so I can't tell you if this is code is causing your problem, or if it is, how to fix it. However, all your other code provides explicit qualifications, like this, which is a best practice:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    03-21-2014
    Location
    NY
    MS-Off Ver
    Excel 2010, 2013
    Posts
    2

    Re: excel vba works from VBA but not from button

    Jeff,


    Thank you for your prompt response.

    I have two sheets
    the pallet header information sheet. This is the sheet that contains all the information such as customer, product, PO, pick update, etc.
    the pallet header template that is just that the template that is being populated by the information from the pallet header info sheet

    the pallet header info sheet is populated by another VBA script that puts in the quantity need (col M) and the order that they should be printed in (col L)
    because i dont know which rows will be filled on a given day i have the worksheet being sorted by column L then have it loop through the for function to fill the pallet head template then print the correct number of copies from column M of the other sheet.


    I had two buttons to do the same thing one on each worksheet so depending on which sheet the user had open they could print.

    I took note of your advice and added the ws14 in front of the unqualified range and it is now working from the buttons.

    Thank you again.

  4. #4
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    365
    Posts
    18,634

    Re: excel vba works from VBA but not from button

    It sounds like this problem is solved. If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

+ 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: 05-25-2020, 03:25 AM
  2. [SOLVED] Reset Button Works Once
    By Praetus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-30-2017, 08:47 AM
  3. Macro works but not as a button
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-18-2016, 02:25 PM
  4. Macro button works on my pc, no-one else's
    By ssu95bm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2015, 01:47 PM
  5. [SOLVED] Excel macro works with keyboard shortcut, but not command button. Please Help.
    By mneches@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-05-2006, 06:35 PM
  6. Excel Addin works that works on a template workbook
    By s.jay_k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2006, 03:35 PM
  7. [SOLVED] How do I convert works file to excel without works software?
    By CatMB in forum Excel General
    Replies: 1
    Last Post: 06-21-2005, 12:05 PM

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