+ Reply to Thread
Results 1 to 4 of 4

Combine parts of macros

  1. #1
    Registered User
    Join Date
    05-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Combine parts of macros

    Hi Guys,
    I have done several excel macros recently using vba which manipulate sheets and workbooks in some complex ways. For example:

    Extract certin data based on a variable entered in a dialogue box.
    Concantinate columb A if critaria meets x.
    Open files in directory :\week xx, where xx is variable input then copy data from one file to another, save and close.
    Complex sort, filter and cut functions with varables.

    These macros are used in different areas but i find that i can combine parts of each with little or no changes to suit other jobs.

    I was wondering would it be possible to create a program or macro where i could do the following:

    1.Choose eliments from the above code's using buttons with function discriptions.
    2.Change the varables in that chosen eliment with input box.
    3.Combine the chosen eliments into a new macro.

    I'd like to distribute this type of macro program to staff to help them create more complex macros in there own rolls with out me.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Combine parts of macros

    Hi,

    The short answer is Yes.

    The trick is to make sure that you break your code down into small generalised procedures which can be called at the appropriate time from any other macros.
    Variables can either be passed from the calling code to the sub procedure, or alternatively a Public Variable may be created which will be valid in any of the macro procedures.

    Difficult to comment in more detail without seeing the specifics of your system.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Combine parts of macros

    Hi Richard,
    Attached is my first macro that takes a database dump from our Erp system and manipulates it in a specific way to give a required report.
    I would be looking to create a database or program where I could divide this macro and several others into their separate elements, for example “find columns with headers and copy to another page”.

    And through multiple element selection and simple user input boxes change the variables to build a new separate custom macro.


    Thanks for your reply
    Regards
    Paul.
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Combine parts of macros

    I must admit I found your macros somewhat impenetrable and rather too long for easy analysis and reading.

    You should aim to keep macro procedures fairly short and concise. Rarely do I find the need to have any procedure more than say 25 lines of code.

    That said I question whether your approach is the most efficient. It seems that you are essentially wanting to filter data based on certain criteria. In which case I would use the straightforward Data Filter Advanced Filter.

    If you have several different reports, hold the column headers for each one in a separate sheet and when you want to create a report copy the appropriate headers to a common anchor cell.

    Create dynamic range names for
    "MyData", The Sales Report data,
    "DataOut" which is the row of report column headers based on the output anchor cell
    "MyCriteria" which is the column headers and selection values.

    Above the DataOut header rows have criteria cells for each of your selection criteria and depending on the report add the relevant criteria. Then you can use a simple macro like

    Please Login or Register  to view this content.

+ 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