|
本帖最后由 ykcbf1100 于 2024-8-28 21:20 编辑
文本数据导入- Sub ykcbf() '//2024.8.28 数据导入
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("Sheet1")
- With Application.FileDialog(msoFileDialogFilePicker)
- .InitialFileName = ThisWorkbook.Path & ""
- .Title = "请选择对应Excel文件"
- .AllowMultiSelect = False
- .Filters.Clear
- .Filters.Add "TXT文件", "*.*"
- If .Show Then f = .SelectedItems(1) Else Exit Sub
- End With
- Set wb = Workbooks.Open(f, 0)
- arr = wb.Sheets(1).UsedRange
- wb.Close 0
- ReDim brr(1 To 100000, 1 To 100)
- For i = 1 To UBound(arr)
- If Val(arr(i, 1)) = 1 Then k = k + 1: d(k) = i
- Next
- For k = 1 To d.Count
- r1 = d(k)
- If k = d.Count Then r2 =UBound(arr) Else r2 = d(k + 1) - 1
- bm = Replace(Split(arr(r1, 1), ":")(1), ")", "") '//上级部门
- st = WorksheetFunction.Trim(Trim(arr(r1 + 3, 1)))
- b = Split(st)
- st1 = CStr(Split(b(0), ":")(1)) '//机构号
- st2 = CStr(Split(b(1), ":")(1)) '//机构名称
- st3 = CStr(Split(b(2), ":")(1)) '//日期
- For i = r1 + 4 To r2
- If Val(Trim(arr(i, 1))) Then
- st = WorksheetFunction.Trim(Trim(arr(i, 1)))
- b = Split(st)
- m = m + 1
- brr(m, 1) = bm
- brr(m, 2) = st1
- brr(m, 3) = st2
- brr(m, 4) = st3
- For j = 0 To UBound(b)
- brr(m, j + 5) = b(j)
- Next
- End If
- Next
- Next
- With Sheets("Sheet1")
- .UsedRange.Offset(2).ClearContents
- .Columns(2).NumberFormatLocal = "@"
- .[a3].Resize(m, 20) = brr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|