|
楼主 |
发表于 2024-6-28 23:23
|
显示全部楼层
- Sub ykcbf() '//2024.6.27 导入TXT文件数据
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Dim arr, brr(1 To 10000, 1 To 6)
- Set sh = ThisWorkbook.Sheets("Sheet1")
- p = ThisWorkbook.Path
- f = p & "\MML任务结果_DSP RRU_20240626_100149.txt"
- Set wb = Workbooks.Open(f, 0)
- With wb.Sheets(1)
- arr = .UsedRange
- wb.Close False
- End With
-
- For i = 1 To UBound(arr, 1)
- If IsError(arr(i, 1)) Then
- arr(i, 1) = "Error 2029"
- End If
- Next
-
- 'On Error Resume Next
- For i = 1 To UBound(arr)
- If InStr(arr(i, 1), "网元 : ") Then k = k + 1: d(k) = i
- Next
- For k = 1 To d.Count
- r1 = d(k)
- If k = d.Count Then r2 = r Else r2 = d(k + 1) - 1
- st = Mid(arr(r1, 1), 6)
- For i = r1 To r2
- If Left(arr(i, 1), 1) = "0" Or Left(arr(i, 1), 1) = "1" Or Left(arr(i, 1), 1) = "2" Or Left(arr(i, 1), 1) = "3" Then
- s = WorksheetFunction.Trim(arr(i, 1))
- b = Split(s)
- m = m + 1
- brr(m, 1) = st
- For j = 0 To UBound(b)
- brr(m, j + 2) = b(j)
- Next
- ElseIf InStr(arr(i, 1), "结果个数") Then
- If Split(Split(arr(i, 1), ")")(0), " ")(2) = 1 Then
- m = m + 1
- brr(m, 1) = st
- brr(m, 2) = Split(WorksheetFunction.Trim(arr(i - 5, 1)), " ")(2)
- brr(m, 3) = Split(WorksheetFunction.Trim(arr(i - 4, 1)), " ")(2)
- brr(m, 4) = Split(WorksheetFunction.Trim(arr(i - 3, 1)), " ")(2)
- brr(m, 5) = Split(WorksheetFunction.Trim(arr(i - 2, 1)), " ")(2)
- brr(m, 6) = Split(WorksheetFunction.Trim(arr(i - 1, 1)), " ")(2)
- End If
- End If
- Next
- Next
- With sh
- .UsedRange.Offset(1).Clear
- If m > 0 Then
- .[a1].Resize(1, 6).Interior.Color = 49407
- With .[a2].Resize(m, 6)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End If
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
- 感谢高手的帮助,有3点我做了修改
- 1、对于查询结果是一条的,做了一下判断
- 2、excel错误数据格式做了处理
- 3、柜号可能不是0的做了处理,我加入了0~3
复制代码 |
|