+ Reply to Thread
Results 1 to 4 of 4

Changing VBA code to return data range, appending to prior data

  1. #1
    Registered User
    Join Date
    08-20-2007
    Posts
    24

    Changing VBA code to return data range, appending to prior data

    All,

    I currently have a VBA macro that I have created. I now need to change this code from what it is, and make it return a new set of data. Here is the current code:

    Please Login or Register  to view this content.
    Basically we have about 80 files that we get each day, and this macro opens all of the files, and gives us the totals in each file. The file names are pretty constant each day, except the date changes on each one (the file is named for each machine).

    What I need for it to do now, is to take all data from the file EXCEPT the last line, and put the info into a new tab of the current worksheet. As it takes the data from file B, it would append to the data in set A, and so on so that the worksheet will have all of the data from all of the files in it. The rest of the macro I can write on my own ( sorting the new data set, and subtotaling it by machine number), but I cannot seem to be able to alter this macro to return the data set I need.

    Any thoughts, hints, tips, anything at all would be majorly appreciated. Thank you for any help that you can be.

    Also, if modifying this code is not the way to go, what are your suggestions?

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    With the current code I notice a couple of things:

    1. Opening files but Close statement missing.

    2. Function ParseDelimitedString looks similar to the Split Function in VBA, see demo below. Is using Split an option for you?
    Please Login or Register  to view this content.
    What I need for it to do now, is to take all data from the file EXCEPT the last line
    In the Do While...Loop read each line from a file into an array and ignore the last element -
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-20-2007
    Posts
    24

    VBA Help

    The VBA code that I posted is a working macro, that we use at our location currently. Not being the best at VBA code, I don't know how the macro behaves specifically, but I do not have to manually close windows of the files it opens. Actually, now that I look at it, not sure how it closes them down...

    Basically I am keeping this first macro to pull the total amount from the files that have data. This next sheet that I need will actually open another set of files (with the same names as before, except with _CTF_ added to the name), and input all items from the file that has data in the 1st column (A). Because the totals column is actually starting in B or C, this may be easier to code. I then would take the range of cells from A1:L (end of the data) and append it on a sheet to data from the other files.

    Because the date changes for every days files that I want to access, would a string work?

  4. #4
    Registered User
    Join Date
    08-20-2007
    Posts
    24

    Vba

    I cannot seem to get Split to work as I would like. Because of the changing names of the file types, I went with the current code. It was easier for me at the time, because I could easily change the files it was looking for by assigning the numbers on another sheet. It was easy to understand, and easy to change if the source files were to move to another directory.

    Can this work with Split as well, or does this change the very nature of the function?

    Also, because the file is a .csv, ParseDelimitedText worked with the comma seperators
    Last edited by camcrazy08; 08-21-2007 at 11:32 AM.

+ 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