+ Reply to Thread
Results 1 to 13 of 13

Combine similar macros into one

  1. #1
    Registered User
    Join Date
    04-08-2013
    Location
    Wajdušna
    MS-Off Ver
    Office 365
    Posts
    79

    Combine similar macros into one

    Hello
    I have one question-request. I have a workbook with 8 different sheets. Cuz i dont know how to write code in VBA, I recorded 8 macros for each individual sheet. What the macro does is gathers the wanted data from that sheets and prints it. And it works great individually. But i have to press 8 buttons to get 8 different .pdf files and then combine them, and there is a lot of the code that is the same in every macro.
    Is any of you willing to take a look at my code and rearrange it so that it will took only one press of a button to print the wanted data from all the sheets (and also cut out the repeating part of the code) ?
    Here is a link to my word.doc that contains all 8 macros: https://dl.dropboxusercontent.com/u/...%20Makro1.docx

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Combine similar macros into one

    why did you attach doc file ? xlsm file would be more useful for testing
    If solved remember to mark Thread as solved

  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: Combine similar macros into one

    Hi, ATOP,

    maybe reduce the code to just one event which is to be inserted into ThisWorkbook and will get fired every time the workbook is printed or the pagepreview is elected:
    Please Login or Register  to view this content.
    @patel45:
    no answer certainly would have been a much better answer - if you canīt help I request that you simply do not post.

    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

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Combine similar macros into one

    Quote Originally Posted by HaHoBe View Post
    if you canīt help I request that you simply do not post.
    you can request what you want, you are forgetting i'm collecting sample workbooks
    Please avoid comment on my answers

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Combine similar macros into one

    Patel,

    There is nothing wrong with providing the code in a word doc. Its not mandatory that it should be provided in a .xlsm file only.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Combine similar macros into one

    I never said it was wrong, I said xls file would be more useful

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Combine similar macros into one

    Ok.

    Holger, Patel also has his viewpoint. He possibly doesnt want to go thru the extra step of moving the code from the word doc to the excel file and prefers directly testing it on the excel file. Its his viewpoint and lets respect it.

    So its best you both continue the good work of helping others and not worry about what the other is saying. If one of you is comfortable with the excel file, use it and if you are comfortable with word, continue. Arguing with each other will not help the forum or the OP.

  8. #8
    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: Combine similar macros into one

    Hi, Arlette,

    I appreciate your efforts to calm things down.

    But I wonīt pass
    you can request what you want, you are forgetting i'm collecting sample workbooks
    Is this a help forum or a chat? Users tend to look at the number of posts by a member and judge the "quality" of any answer even from that, so any posting of whatever quality will be helpful for that kind of "reputation". Does any of patel45īs posts in this thread help the TO to solve the problem? I really appreciate your answer on that - speaking for myself: if I canīt answer a question put in any forum I pass that - maybe some other user has a better understanding of the problem or can imagine a solution to that. Thatīs my point - patel45īs POV is in the quote?

    I know how difficult it is to be of any help to users (believe it or not - Iīve even gone through the moderating stuff on a forum for more than a decade by now) and I wonīt buy that - that all (no, no excuse on foreign languages accepted here - english is definitely not my native tongue but I can at least try to improve my skills on it, thatīs one of the reasons an old dog like me has taken a more active part since August of last year than in the first seven years of my membership with this forum).

    And personally I like best
    Please avoid comment on my answers
    For Each ... Step 2 patel45 has spoken - please, no comments on the Step 2.

    Ciao,
    Holger

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Combine similar macros into one

    Ok, maybe we 3 can take this offline, instead of bombarding this OP's thread. Let the guy not get confused and get the solution he needs.

  10. #10
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Combine similar macros into one

    The chat was started from HaHoBe with
    @patel45:
    no answer certainly would have been a much better answer - if you canīt help I request that you simply do not post.
    this does not help TO to solve the problem.
    HaHoBe likes my claim to avoid comment on my answers ?
    I hope he will do it, I will report all his comments to my answers

  11. #11
    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: Combine similar macros into one

    Hi, ATOP,

    the code for the buttons as well as the code for printing all sheets in Module3 looks like this:
    Please Login or Register  to view this content.
    Two global variables are used to hold the name of the Sheet and the Range respectively. In ThisWorkbook the code looks like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  12. #12
    Registered User
    Join Date
    04-08-2013
    Location
    Wajdušna
    MS-Off Ver
    Office 365
    Posts
    79

    Re: Combine similar macros into one

    Thank you

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Combine similar macros into one

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.

+ 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