+ Reply to Thread
Results 1 to 7 of 7

Macro to combine a Text File & Excel file into one Separate workbook

  1. #1
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    638

    Macro to combine a Text File & Excel file into one Separate workbook

    I have 2 Files that I would like to combine into one workbook- each having its own TAB AT BOTTOM. I would like to open a excel spreadsheet named "Comparison" and have a button "Macro" that when chosen it would ask for the first file to import and then you would select the Text File (Pason Data Run 1) and it would import it into its own tab with the excel sheet.

    One of the problems I have when importing the text file is 2 of the columns I would like married together as one. ( Date & Time ) on the new worksheet and the other data in there own respective columns
    I would like the date and time to read like ( ex: "8/12/14 06:01" )

    I have included an excel sheet showing (Pason data run 1) after I imported it manually - notice that column (a,b,c) are highlighted Coulumn 'A' would not format as date so I had to create column 'B' and manually enter in the dates then in Column 'D' I combine column (C & B) to make my date and time format.

    then you could run another macro for the Excel sheet (well Guide Run 1) to import into its own tab with in the new workbook.

    I use both Files (Pason Data run 1 & Well guide Run 1) to run a correlation log and I need the date and times the same for that to happen.

    This is some code I have partially working
    Please Login or Register  to view this content.
    Once that imports I go into the first text file that got imported and I have to combine 2 of the cells to have the date & time together. I used this code to start but I do not know how to get the format to carry all the way down the sheet.
    Please Login or Register  to view this content.
    It would be great if I could add this somehow to the first original text file that is imported and have it do this seamlessly.
    Also How can I get the Macro to Paste the 2 files into the existing open workbook and not start a new one
    Last edited by bdouglas1011; 08-28-2014 at 10:07 AM. Reason: Added some code I am trying

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    The macro in the attached will do the import and date/time stamping....

    Well Guide Run 1.xlsm

    Here's the code:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    638

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    That worked awesome I then created another button for my other file and just modified it for Comma Delimited for it to import into another tab and all is good up to this point.

    My next task is to Take the 2 newly created worksheets and combine them into a correlation log.

    I am looking for my New Date & time from the Pason Data to Correlate with the Corr. Date column on the other sheet.

    I attached the way it is now and added the Log worksheet that shows how this was done manually Notice that the Columns highlighted red are form the Pason data that is brought over and correlated up with the time on the Well guide sheet.

    How would I add new Button that would combine these 2 sheets

    I have quite a few things I am trying to do and I figured breaking it up would be easier

    Thanks again your great
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    I cannot figure out what you want with that file. Could you shorten your data, and show with before and after version, what you want and where the data came from? You can just copy and paste the values of interest, and use color coding to show their source, and maybe some explanation of what "correlated up" means .....

  5. #5
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    638

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    Here goes I am trying to explain best I can I hope this helps.

    It is hard to explain -- I have attached 2 files (1) "Snapshot of finished correlated Log" & (2) "Combine Corr Log with Initial Import Macros"

    On the first "Snapshot of finished correlated Log" it shows you how the correlation is set up under Tab 'Correlated Log' and that information is highlighted Red
    It pulled that data from the Tab "WG205RUN1PASONDATA" and under that tab the information I highlighted Blue is where the VLOOKUP gets its info from

    Now On the other sheet "Combine Corr Log with Initial Import Macros" - I have included the Import macros under sheet 1 - Then the next 2 Tabs are the actual TXT files that got imported. I have
    removed a lot of the data going down the sheet because it is quite large, but now the next tab is "Unfinished Correlated Log" & I want that to replicate the correlated Tab form the Snapshot file I
    provided on the other sheet.

    What they have been doing is making a copy of the 2nd Tab "WG205RUN1gda_log" and then merging all the data from "WG205RUN1PASONDATA" Tab using VLOOKUP - Once they begin they start by

    Adjusting the "Corr. Date Column" by subtracting (0.291666666666667) from the (Date column) all the way down the sheet.

    Then they have been just inserting new columns and using VLOOKUP merging the 2 sets of data. and do that for all the columns that were highlighted in red on the Snapshot file.

    I have already Inserted Columns to help you know where it goes but the Snapshot file shows you also with it all together.

  6. #6
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    638

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    Maybe this help clarify :

    I would like to insert a column at "g" and Inset this VLOOKUP "=VLOOKUP('Unfinished Correlated Log'!F3,WG205RUN1PASONDATA!$C$2:$N$5281,2) into that cell

    PS is there a way to change the formula to read all the way down the sheet to capture any data in that range -- Right now my range is c2:n5281 but that changes depending on how big the log is?

    I want the column to have the header Title "Hole Depth" And I would like this to continue down the whole Column. Also the Column has to be formatted as number with 2 dec places.

    This is the first Column Once I get a macro to complete this one I would just need to add the other columns in the same format just change my VLOOKUP formula

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    Try changing your macro to this, which will add 12 columns of the VLOOKUP formulas to pull data from the just-opened file:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Houston, TX
    MS-Off Ver
    office 365
    Posts
    638

    Re: Macro to combine a Text File & Excel file into one Separate workbook

    Maybe I should start from scratch. I have included the excel sheet which sheet1 has both initial macros first use Import Pason and then use the import LOG that will create the
    files and hopefully you can modify the last one for LOG to include all the items on my VLOOKUP NOTES that are attached-- I have included the text files for you to be able and import this is the only way to keep the files small to attach they are quite large even though text files

    I know its a lot but I really could use some help

    Thanks in advance
    Attached Files Attached Files
    Last edited by bdouglas1011; 08-29-2014 at 03:49 PM.

+ 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. Macro to combine a Text File & Excel file into one Separate workbook
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2014, 03:23 AM
  2. Replies: 2
    Last Post: 04-12-2013, 07:56 PM
  3. Replies: 1
    Last Post: 02-23-2013, 08:36 AM
  4. Macro button to separate workbook as a file name referenced from cell.
    By Moonpie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2012, 12:19 PM
  5. Can you e-mail separate sheets in an Excel Workbook file?
    By FruityPebbles in forum Excel General
    Replies: 5
    Last Post: 04-01-2012, 03:05 AM

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