从文本文件导入数据并对其进行sorting

我正在处理很多pcb项目,我们有一个excel文件,我们必须手动input很多值(实际上是一个钻取表)。 我现在有一些问题

  1. macros不保存

当我创build导入文本的macros时,我可以保存它,但是当我再次打开Excel文件时,macros就不见了。

这里是我用来导入文件的代码:

Option Explicit Sub ImportTextFile() Dim fName As String fName = Application.GetOpenFilename("Text Files, *.tap; *.drl") If fName = "False" Then Exit Sub With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fName, _ Destination:=Range("$A$1")) .Name = "sample" .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 = xlTextQualifierNone .TextFileConsecutiveDelimiter = True .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .TextFileOtherDelimiter = "" & Chr(10) & "" .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, _ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 End Sub 
  1. sorting值

一旦我有我的报告导入,它看起来像这样:

 ;HEADER: 271-138-131-011 ;CODE : ASCII ;FILE : ncdrill-1-10.drl for ... layers TOP and BOTTOM ;DESIGN: 131-011.brd ;T01 Holesize 1. = 20.000000 Tolerance = +2.000000/-2.000000 PLATED MILS Quantity = 360 ;T02 Holesize 2. = 24.000000 Tolerance = +2.000000/-2.000000 PLATED MILS Quantity = 712 ;T03 Holesize 3. = 126.000000 Tolerance = +3.940000/-3.940000 PLATED MILS Quantity = 10 ;T04 Holesize 4. = 79.000000 Tolerance = +3.000000/-3.000000 NON_PLATED MILS Quantity = 1 ;T05 Holesize 5. = 118.000000 Tolerance = +0.000000/-0.000000 NON_PLATED MILS Quantity = 3 % G90 T01 X-0017100Y0160000 X-0017000Y0180000 Y0200000 Y0220000... 

我其实需要拿出洞的大小和数量。 我连续使用这个函数来取大小=IF(A18="";"";RIGHT((LEFT(A18;26));7)) 。 对于数量,我不知道该怎么做。

一旦我有我的洞的大小和数量,我想报告他们在桌子上。

我应该写什么函数或macros?

感谢您的帮助。