+ Reply to Thread
Results 1 to 8 of 8

Adjust existing macro to pick up specific named worksheet and copy to named range

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Adjust existing macro to pick up specific named worksheet and copy to named range

    Hi everyone,

    I have an existing macro which works pretty well. I currently run through all workbooks in a folder, identifies worksheet names which match worksheet names in the master workbook and copies the data from the external workbook worksheet to the master workbook worksheet. What I'm trying to do is adjust the macro to do the following:

    1. run through each workbook in a folder
    2. if the workbook name equals a cell value in ThisWorkbook.Sheet1.range("B2:B50") then copy Worksheet("ABC") entire used range into Workbooks(2) with the worksheet that matches the external workbook name.
    3. move to the next cell in the range and repeat as above

    So for example, lets cell B2 in ThisWorkbook.Sheet1.range("B2:B50") = "Stuff"
    The macro will find workbook.name = "Stuff" and copy the used range in Workbooks("Stuff").Worksheets("ABC")
    The master will paste this used range into Workbooks(2).Worksheets("Stuff")
    Then move onto the cell B3 in ThisWorkBook.Sheet1.range("B2:B50")

    Below is the macro as I have it. It doesn't work with the adjustments I've tried to make:

    Please Login or Register  to view this content.
    Any ideas?

    Thanks!!
    Last edited by Groovicles; 06-06-2017 at 11:11 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    You could try this.
    It assumes that the "Master" has been saved in the same folder.
    Not tested so make sure to try with copies of your file(s)
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    Hi jolivanes,

    Thanks for your code. I'm trying my best to understand it. The macro as I currently have it is housed in the ThisWorkbook. It then prompts the user to select the Summary file which becomes Workbooks(2). The macro then prompts the user to identify where the actual external files are located. The results in these external files are supposed to be copied into Workbooks(2). I'm not certain I see how that works in your code? Can you clarify?

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    I thought I answered as per your explanation. I did not look at your code as it does not do what you want it to do.
    I'll have a look later when I have some time again.
    Sorry about that.

  5. #5
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    So here's what I have now. Its close but not quite doing what I need.

    What its not doing right:

    1. Its only pulling opening the first workbook in the folder rather than looking for the file indicated in myFile.
    2. its also not looping through the list of cells in I
    3. Its not renaming the copied worksheet to the i value

    What it is doing right:

    1. Copying the correct worksheet from the newly opened workbook to the correct position in Workbooks(2)

    Please Login or Register  to view this content.
    Any ideas?

    Thanks!

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    I don't get your logic.
    Why would you "run through each workbook in a folder" to see if it's name is the same as in one of the cells in a range. (See Post #1, #1 and #2)
    Why not use the cells in the range to open that particular workbook?
    I can't make head or tails out of the code you have in Post #5 either.

    Do you want to open all the files in a range in your active (call it Master for now) workbook and copy the used range from a sheet named "ABC" in that opened workbook into your Master?
    I am terrible reading/understanding someone's code that does not work.
    Either explain properly what you want to achieve or maybe someone else understands the code.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    I tried to get your code from Post #5 to work but wasn't able to.
    Could you go through the motions and explain what should, or what you want to, happen at each line.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Adjust existing macro to pick up specific named worksheet and copy to named range

    Try this. It might be a start of what you're after.
    You have to change all the references like sheet names ans cells ranges as required.

    Please Login or Register  to view this content.
    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)

Similar Threads

  1. [SOLVED] vba code to add modulable no of named worksheets after the last existing named sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2017, 08:48 AM
  2. Copy values of all named range in wb1 to identically named ranges in wb2
    By JAMIAM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-24-2016, 06:58 PM
  3. Copy specific cell(s) or named range from one workbook to another
    By gcoug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2012, 06:01 PM
  4. Replies: 3
    Last Post: 06-04-2011, 10:56 AM
  5. Adding a new row into an existing named range in a macro
    By topper in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2009, 10:25 AM
  6. Need to adjust existing named range for dynamic charts
    By tbonejo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2006, 12:18 PM
  7. [SOLVED] create named range specific to worksheet
    By beliavsky@aol.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2005, 12:05 PM

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