View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Nila Nila is offline
external usenet poster
 
Posts: 7
Default Excel VBA help: Text file formatting

On Friday, June 6, 2014 11:25:39 PM UTC-6, Nila wrote:
On Friday, June 6, 2014 5:53:49 PM UTC-6, L. Howard wrote:

Step 5 is done by "sub sort". This is where I am getting a compile error "Sub or function not defined". I am new to excel vba, I am not able to narrow down the issue further. Could anyone help me on this issue please? TIA.








This is an outright shot in the dark, but I made these changes on the Sort sub. Does not error and produces a new worksheet each time I run it in a workbook with no data.








The name of the sub is purposefully change, as it produced an error. I presume "sort" is a reserved word for Excel.








Change the sheet names back to suit your workbook.








Regards,




Howard








Sub Mysort()








Dim x As Integer




Dim y As Integer




Dim erow As Range








y = 10




x = 2




Sheets.Add after:=Sheets(Sheets.Count)




Do While Cells(1, x) < ""




If Cells(1, x) = "##RETENTION_TIME" Then




Sheets("Sheet2").cell(1, x).Copy




Sheets("sheet1").Activate




Set erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row




ActiveSheet.Paste destindation:=Worksheets("sheet1").Range("erow" & ":" & "A" & "y")




End If




Sheets("Sheet2").Activate




x = x + 1




Loop








End Sub




Thanks Howard, But it didn't work. Is there any way I can attach files in this forum?


This is my input file structure(Sample not the actual file)

##SCAN_RANGE= 30,300
##SCAN_TIME_UNITS= Seconds
##XUNITS= m/z
##SCAN_NUMBER= 1
##RETENTION_TIME= 0.600
##TIC= 93832
##NPOINTS= 10
##XYDATA= (XY..XY)
30.92,269
30.99,317
32.59,302
33.26,337
34.86,492
34.99,316
36.66,319
37.79,295
38.92,269
38.99,262
##SCAN_NUMBER= 2
##RETENTION_TIME= 1.100
##TIC= 88976
##NPOINTS= 10
##XYDATA= (XY..XY)
30.39,157
31.52,221
32.72,321
33.26,263
34.46,317
35.52,289
36.66,361
37.85,313
37.99,157
39.65,246
##SCAN_NUMBER= 3
##RETENTION_TIME= 1.600
##TIC= 92650
##NPOINTS= 10
##XYDATA= (XY..XY)
30.46,199
31.12,284
32.79,339
33.39,337
33.99,272
35.66,317
36.85,458
36.99,384
37.99,232
39.65,425
##SCAN_NUMBER= 4
##RETENTION_TIME= 2.100
##TIC= 88625
##NPOINTS= 10
##XYDATA= (XY..XY)
30.59,164
31.12,316
32.26,285
33.46,353
34.12,335
35.19,351
36.32,290
37.52,284
38.59,278
39.79,414
##END=

I'm expecting my output file to be (Sample not the actual file)

0.6 30.92 269
0.6 30.99 317
0.6 32.59 302
0.6 33.26 337
0.6 34.86 492
0.6 34.99 316
0.6 36.66 319
0.6 37.79 295
0.6 38.92 269
0.6 38.99 262
1.1 30.39 157
1.1 31.52 221
1.1 32.72 321
1.1 33.26 263
1.1 34.46 317
1.1 35.52 289
1.1 36.66 361
1.1 37.85 313
1.1 37.99 157
1.1 39.65 246