Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2018, 06:00 AM
norcross norcross is offline importing and xonditioning data from a text file Windows 8 importing and xonditioning data from a text file Office 2010 64bit
Novice
importing and xonditioning data from a text file
 
Join Date: Mar 2018
Posts: 2
norcross is on a distinguished road
Default importing and xonditioning data from a text file

Hello everyone.
I searched over the forum for a solution but couldn’t find one.
I have a text file that is updated daily by adding more rows.
This is how the text file looks,except there are hundreds of rows:

When importing this data into EXCEL I only need certain values to appear from each row(CD,UNIT,Oper,VAL,DateTime)so I manually delete most of the columns to get just the data I need,like this:

What is the best way to automate this process?
Will appreciate your help.
Reply With Quote
  #2  
Old 03-14-2018, 09:02 AM
NoSparks NoSparks is offline importing and xonditioning data from a text file Windows 7 64bit importing and xonditioning data from a text file Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Can you post a sample workbook with a dozen or so records ?
On one sheet what you're starting with and on another sheet what you want to end up with.
Thanks
Reply With Quote
  #3  
Old 03-14-2018, 09:59 AM
norcross norcross is offline importing and xonditioning data from a text file Windows 8 importing and xonditioning data from a text file Office 2010 64bit
Novice
importing and xonditioning data from a text file
 
Join Date: Mar 2018
Posts: 2
norcross is on a distinguished road
Default

Thanks for reply,
TXT is original file and XLSX is the file I am trying to get.
Attached Files
File Type: txt uroven121.txt (6.2 KB, 10 views)
File Type: xlsx uroven121.xlsx (10.7 KB, 8 views)
Reply With Quote
  #4  
Old 03-14-2018, 01:53 PM
NoSparks NoSparks is offline importing and xonditioning data from a text file Windows 7 64bit importing and xonditioning data from a text file Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Try giving this a test run.

I used the macro recorder for importing the text file using semicolon and equal sign as delimiters.
Then wrote a little macro to delete some columns, split the date/time to adjacent cells and delete the original date/time column.

Paste this into a standard module of a new workbook.
You'll need to adjust for your own text file location.

Code:
Sub ImportTextFile()
'
' as recorded by macro recorder
'
Application.ScreenUpdating = False

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;D:\Forum Stuff\2018\2018_03_01\norcross\uroven121.txt", Destination:= _
        Range("$A$1"))
        .Name = "uroven121_5"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = "="
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    
Call Manipulate
    
Application.ScreenUpdating = True

End Sub



Private Sub Manipulate()

    Dim lr As Long
    Dim cl As Range
    
With ActiveSheet
    .Range("A:C,E:G,I:I,K:K,M:S").Delete Shift:=xlToLeft

    lr = .Cells(Rows.Count, "E").End(xlUp).Row
    For Each cl In .Range("E1:E" & lr)
        cl.Offset(, 1).Resize(, 3).Value = Split(Trim(cl.Value), " ")
    Next cl
    .Columns("E").Delete Shift:=xlToLeft
End With
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to extract specific data from text file using vba victor92 Excel Programming 0 12-01-2017 12:53 AM
importing and xonditioning data from a text file Importing Data from seperate closed excel file KingoftheKassel Excel Programming 1 06-10-2016 08:34 AM
An error occurred while importing this file <image file> melvinjn Drawing and Graphics 1 01-19-2015 01:32 AM
importing and xonditioning data from a text file How to convert a text file to an Excel file with the data format automatically? mradmin Excel 6 10-16-2013 10:34 AM
importing and xonditioning data from a text file extracting data from Table to text file Anirudh_Dsp Word Tables 1 05-23-2010 07:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft