+ Reply to Thread
Results 1 to 5 of 5

Simplify macro

  1. #1
    Registered User
    Join Date
    01-28-2011
    Location
    any town, usa
    MS-Off Ver
    Excel 2010
    Posts
    16

    Simplify macro

    I need help simplifying this macro:

    I run a report for every hour of the day.
    A text file is saved into a directory as the following (0100 = 1:00 AM, 0200 = 2:00 AM, etc):

    sv_toptrans 0100 FI.txt, sv_toptrans 0200 FI.txt, sv_toptrans 0300 FI.txt... sv_toptrans 2200 FI.txt, sv_toptrans 2300 FI.txt, sv_toptrans 2400 FI.txt (1 file for each hour - 24 files total)

    I need the macro to look in the directory. Then copy the data to 'sheet1'. Then format the data. Finally move the data to to differernt worksheets.

    This macro works as long as a have a text file for each hour.

    If there is not a text file for a particular hour, I need the macro to skip it and move to the next hour. For example, if there is a sv_toptrans 0100 FI.txt file, it should copy the text file to the workbook, format it and then move the data to the different worksheets and then go to the sv_toptrans 0200 FI.txt file. If there is not a sv_toptrans 0200 FI.txt file, then it should move onto the sv_toptrans 0300 FI.txt file. If there is a sv_toptrans 0300 FI.txt file, it should format it and then move the data to the different worksheets and then go to the sv_toptrans 0400 FI.txt file.

    ================================================================

    Please Login or Register  to view this content.
    *** I repeat this for all 24 hours ***
    Last edited by iamasimpleman; 01-29-2011 at 11:43 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: I need help simplifying this macro.

    Hi iamasimpleman

    Welcome to the Forum

    Please wrap your code in code tags, before the moderators get you...

    Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.

    Cheers

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Simplify macro

    Try this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    01-28-2011
    Location
    any town, usa
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Simplify macro

    Thank you JBeaucaire. This is exactly what I was looking for. Thanks for all the help.

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Simplify macro

    hi everyone,

    I haven't tried JB's code but I suggest one small change to it, because I think you may end up with a lot of redundant ("duplicate") connections in your workbook if the code is repeatedly run. Of course, I could be wrong...

    Please Login or Register  to view this content.
    iamasimpleman,
    If you're happy with JB's solution, can you please mark the thread as Solved?
    (see Rules for details)

    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

+ 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