rnordquest
New member
I need a macro to open the following text file in probably Fixed Width format to get data into separate aligned columns. My problem is that I don't want to have to individually adjust the fixed width for each of the 400 or so files I want to process.
The example shows only the first 2 of 6 data points and of course not all of the file. The number of data points varies. In real life the data columns do line up. They didn't in the preview post.
Diaphragm Type: Floating Fuel LHV: 18573.2
PT Type: J Plus Fuel Spec Grav: 0.8137
Num Points: 6 Airflow Meas: No
OBSERVED DATA/RECORD NO 1 2
N1 (RPM) 48644 49536
N2 (RPM) 33246 33285
Dyne Torque (Ft-Lbs) 236.4 262.6
_________________
Here is what I have for a macro so far:
Index = 2
For i = 1 To 1000
fileToOpen = Application.GetOpenFilename
If fileToOpen <> False Then
Workbooks.OpenText Filename:=fileToOpen _
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, OtherChar:="|", _
FieldInfo:=Array(Array(0, 1), Array(26, 1), Array(60, 1), Array(75, 1), Array(80, 1), _
Array(84, 1)), TrailingMinusNumbers:=True
End If
SalesWorkbook = ActiveWorkbook.Name
Range("A8").Copy
Workbooks(ThisWorkbook.Name).Activate
Sheets("Sheet1").Select
Cells(Index, 1).Select
ActiveSheet.Paste
Workbooks(SalesWorkbook).Activate
Range("B7").Copy
Workbooks(ThisWorkbook.Name).Activate
Cells(Index, 2).Select
ActiveSheet.Paste
Workbooks(SalesWorkbook).Activate
Range("A22:H24").Copy
Workbooks(ThisWorkbook.Name).Activate
Cells(Index, 3).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
As you can see, all I want to do is copy and paste chunks of data from the text files to a single Excel file.
Thanks,
Roger
The example shows only the first 2 of 6 data points and of course not all of the file. The number of data points varies. In real life the data columns do line up. They didn't in the preview post.
Diaphragm Type: Floating Fuel LHV: 18573.2
PT Type: J Plus Fuel Spec Grav: 0.8137
Num Points: 6 Airflow Meas: No
OBSERVED DATA/RECORD NO 1 2
N1 (RPM) 48644 49536
N2 (RPM) 33246 33285
Dyne Torque (Ft-Lbs) 236.4 262.6
_________________
Here is what I have for a macro so far:
Index = 2
For i = 1 To 1000
fileToOpen = Application.GetOpenFilename
If fileToOpen <> False Then
Workbooks.OpenText Filename:=fileToOpen _
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, OtherChar:="|", _
FieldInfo:=Array(Array(0, 1), Array(26, 1), Array(60, 1), Array(75, 1), Array(80, 1), _
Array(84, 1)), TrailingMinusNumbers:=True
End If
SalesWorkbook = ActiveWorkbook.Name
Range("A8").Copy
Workbooks(ThisWorkbook.Name).Activate
Sheets("Sheet1").Select
Cells(Index, 1).Select
ActiveSheet.Paste
Workbooks(SalesWorkbook).Activate
Range("B7").Copy
Workbooks(ThisWorkbook.Name).Activate
Cells(Index, 2).Select
ActiveSheet.Paste
Workbooks(SalesWorkbook).Activate
Range("A22:H24").Copy
Workbooks(ThisWorkbook.Name).Activate
Cells(Index, 3).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
As you can see, all I want to do is copy and paste chunks of data from the text files to a single Excel file.
Thanks,
Roger