+ Reply to Thread
Results 1 to 5 of 5

Edit consolidation macro to make it usable in any workbook

  1. #1
    Registered User
    Join Date
    04-12-2016
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    4

    Edit consolidation macro to make it usable in any workbook

    I am creating a template workbook which consists of a project forecast sheet for any number of projects and with a summery sheet at the begging. Each sheet is identical so, I created a macro to sum a range of data from each project sheet (R7C7:R18C16) and to place it in the same location on the summery sheet (Range("G7").Select). The macro works wonderfully and I have since attached it to a button. The idea is, the end user would be able to manipulate the data within the range R7C7:R18C16 of any project sheet and then re-run the macro by clicking the button within the summery sheet. Unfortunately, the macro recorded the exact file path of my workbook.

    Question 1.) Is there a way to write this Macro so it will work in any active workbook? Meaning, once a project manager relabels/saves the workbook in a different location with a different name, the macro will still perform.

    Question 2.) Can the macro be written such that the worksheet name can be altered and not affect the algorithm? As of right now, if the tab name of any project sheet is changed, the macro will no work.

    Question 3.) Is there a way to write the macro to an undetermined amount of project sheets? In the example below I only have 6, but if an end user were to add 6 more projects, I would like the macro to collect all 12 in the summery.
    I have trouble shot this all day with not much to show for it and would be greatly thankful for any help or thoughts. Thanks!

    RH


    Here is my code to date:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: Edit consolidation macro to make it usable in any workbook

    You will need to give the code at least a folder to search in, a good place to start would be the folder the VBA project is stored in.

    Please Login or Register  to view this content.
    this will give you that folder.

    again you will need to define a rule for which files to open or which files to work on.

    if there is something similar between all their filenames you can loop through all the files in the folder and compared the names

    look into Dir() function (very easy to use), or look into FileSystemObject (more functionality, but needs a reference to scripting for that).

    or if you dont want to go filename route you could setup your macro to look for landmarks within the sheets, look for table layouts, titles, something that would only be in the sheets your looking for.

    anyway just some ideas there you need to think about you need to find some logic to work and set some rules from if this is going to work.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Edit consolidation macro to make it usable in any workbook

    This macro will loop through the sheets and build the array based on your three criteria. You have to edit the two Sheet1 to the code name of your actual summary sheet. Using the code name within the macro will disregard the tab name should it change. In this pictured example, the sheet with the tab name Budget is the code named Sheet3. Replace Sheet1 with your code name for your summary sheet.
    code-name.gif

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    04-12-2016
    Location
    Raleigh, NC
    MS-Off Ver
    2010
    Posts
    4

    Re: Edit consolidation macro to make it usable in any workbook

    AlphaFrog - this was the ticket. And I didn't have to change Sheet1 at all either. I greatly appreciate the help. Karma points heading your way

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Edit consolidation macro to make it usable in any workbook

    You're welcome. Thanks for the karma.

+ 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: 2
    Last Post: 10-12-2015, 04:35 PM
  2. Make workbook read only with no ability to save or edit
    By mmazz365 in forum Excel General
    Replies: 2
    Last Post: 02-04-2015, 02:45 PM
  3. edit macro to make it run on all files in a folder
    By rohit43 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-09-2013, 05:46 PM
  4. Add Filter Field for Workbook Consolidation Macro
    By mlegge04 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2012, 12:43 PM
  5. Macro edit to make it more robust (accounting for annomalies)
    By ad9051 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2012, 11:43 AM
  6. make macros usable! make instructions in plain english !!!!
    By Brainless_in_Boston in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-02-2006, 11:30 AM
  7. [SOLVED] In EXCEL2000, How can I copy a file and make it usable in MS WORK
    By TampaDog in forum Excel General
    Replies: 1
    Last Post: 09-15-2005, 10:05 AM

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