LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Faster way to read data from old file to new

I am having to convert several files of data from an old DOS program and
read them into Excel.
Each file has between 10,000 and 12,000 records of 229 bytes
The records are all contiguous data within the files, with Chr(255)+Chr(255)
determining the start of each new record.
With Excel 2007, I was able to easily use DataText to Columns, setting
Chr(255) as the delimiter and each record of 227 bytes (without the
Chr(255)'s) was created in a separate column on row 1 of the file.
A simple CopyPaste SpecialTranspose allowed me to turn this into 10,139
rows (for the first file) each with 227 characters in column A.

Each of these 227 byte records, is made up of 67 fields of varying lengths.
These I have listed on another sheet with the length of each field and it's
starting position.

Whilst the short piece of code shown below does work and extracts all of the
data into the relevant columns for me, I was wondering whether there was any
faster way of effecting the conversion.
I am using Vista SP1 and XL2007 SP1

Sub CreateRecords()

Dim wss As Worksheet, wsd As Worksheet, wst As Worksheet
Dim i As Long, j As Long, lr As Long, start As Long, length As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wss = ThisWorkbook.Sheets("OldData")
Set wsd = ThisWorkbook.Sheets("NewData")
Set wst = ThisWorkbook.Sheets("Definition")

lr = wss.Cells(Rows.Count, "A").End(xlUp).Row

For j = 2 To lr
' row 1 on Source is blank, row 1 on Destination is a Header row
For i = 1 To 67
start = wst.Cells(i, 3).Value: length = wst.Cells(i, 2).Value
wsd.Cells(j, i) = Mid(wss.Cells(j, 1), start, length)
Next i
Next j
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

--

Regards
Roger Govier

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
read data element from XML file Steve Moreno Excel Programming 2 November 26th 18 08:03 AM
Read data from an htm file Mayank Gupta Excel Programming 1 March 22nd 07 10:01 AM
Read data from anohter XLS file John Whitehead via OfficeKB.com Excel Worksheet Functions 6 July 31st 05 10:20 PM
Read data from a text file (*.txt) Adrian T Excel Programming 0 June 4th 04 10:00 PM
VBA to read data from XL and import into another XL file Steve D[_4_] Excel Programming 0 August 28th 03 04:34 PM


All times are GMT +1. The time now is 04:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"