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
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.![]()
Sub CombineTextFiles() Dim FilesToOpen Dim x As Integer Dim wkbAll As Workbook Dim wkbTemp As Workbook Dim sDelimiter As String On Error GoTo ErrHandler Application.ScreenUpdating = False 'sDelimiter = "|" FilesToOpen = Application.GetOpenFilename _ (FileFilter:="Text Files (*.txt), *.txt", _ MultiSelect:=True, Title:="Text Files to Open") If TypeName(FilesToOpen) = "Boolean" Then MsgBox "No Files were selected" GoTo ExitHandler End If x = 1 Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x)) wkbTemp.Sheets(1).Copy Set wkbAll = ActiveWorkbook wkbTemp.Close (False) wkbAll.Worksheets(x).Columns("A:A").TextToColumns _ Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=False, _ Tab:=False, Semicolon:=False, _ Comma:=True, Space:=False, _ Other:=False, FieldInfo:=Array(Array(1, 5), _ Array(2, 1)), TrailingMinusNumbers:=True x = x + 1 While x <= UBound(FilesToOpen) Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x)) With wkbAll wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count) .Worksheets(x).Columns("A:A").TextToColumns _ Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=False, _ Tab:=False, Semicolon:=False, _ Comma:=True, Space:=False, _ Other:=False, FieldInfo:=Array(Array(1, 5), _ Array(2, 1)), TrailingMinusNumbers:=True End With x = x + 1 Wend ExitHandler: Application.ScreenUpdating = True Set wkbAll = Nothing Set wkbTemp = Nothing Exit Sub ErrHandler: MsgBox Err.Description Resume ExitHandler End Sub
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.![]()
Sub CombineDateTime() Columns("C:C").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove Range("C2").Select ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]" Range("C2").Select Selection.NumberFormat = "dd-mmm-yy hh:mm" End Sub
Also How can I get the Macro to Paste the 2 files into the existing open workbook and not start a new one











LinkBack URL
About LinkBacks


Register To Reply
Bookmarks