+ Reply to Thread
Results 1 to 7 of 7

Cycling through workbooks

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,954

    Cycling through workbooks

    I had a crash and am having to rebuild some code. Using the example below, one area I'm having trouble with is in the "DO YOUR CODE HERE", "PsuedoCode" part. My overall operation is to manipulate pivot tables in and copy data from various files and paste into a single worksheet. My two pain points are:

    1) For my first workbook I want to paste Headers and data, for the all the rest just the data. I'm looking for an elegant way to differentiate just those steps for my first WB, without having to have two really long steps that are basically the same other than headers and LastRow.
    2) Instead of all the files in a folder I need to open 4 specific files. How would I plumb that into the code below?
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Cycling through workbooks

    Hi,
    1) I would bind some flag at the beginning of code like FirstFile=0. Then in Pseudocode section I could check is it first file or not.
    If FirstFile=0 then Copy header+data AND FirstFile=1 else Copy data only
    All next files will go throw Else statement and copy only data. After this short IF - manituplation should be probably the same for all files.
    2) If you could add some special simbols in those 4 file names you could check file name before open it.

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,954

    Re: Cycling through workbooks

    Good idea on 1). On 2), the files aren't mine, so can't add to the filenames.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Cycling through workbooks

    Hi,

    I would suggest an array of the four file names and simply loop through it. I would also note that Application.Filesearch hasn't worked since Office 2003.
    Please Login or Register  to view this content.
    Last edited by xlnitwit; 12-09-2016 at 12:07 PM.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Cycling through workbooks

    Hi jomili,

    If you are pulling in multiple workbooks and extracting stuff from each and doing this over an over again, this sounds like a problem for Power*Query. PQ has the ability to suck in data from multiple workbooks and extract (filter) the data you want from all of them. Time to start learning about it? I've been using it a lot since working through the examples in the "M is for Data Monkey" book.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,954

    Re: Cycling through workbooks

    MarvinP,

    That's the right solution, but unavailable to me at the present time.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,954

    Re: Cycling through workbooks

    MarvinP,
    That's the right solution, but unavailable to me at the present time.

    XlNitWit,
    I'm rocking with your solution. Thanks!

+ 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. Cycling through Sheets
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2016, 10:24 AM
  2. Why my workbooks stop cycling my Macro's ??
    By black7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2013, 04:11 PM
  3. [SOLVED] Multitude of random errors when cycling through workbooks in a folder to copy a range
    By LXN in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-23-2013, 12:29 PM
  4. Replies: 1
    Last Post: 10-10-2012, 07:09 AM
  5. Cycling Formula
    By yinyang in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2007, 05:44 PM
  6. [SOLVED] Not cycling through each sheet
    By Michael Smith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2006, 03:50 PM
  7. cycling through columns?
    By Kirk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2005, 03:06 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