|
本帖最后由 yayahzmeng 于 2017-1-17 22:04 编辑
- Sub 导入()
- Application.ScreenUpdating = False
- Dim file, itxt, wtxt, arr, n%, i%, j%, shname, k%
- file = ThisWorkbook.Path & "\温度湿度.txt"
- Open file For Input As #1
- Do While Not EOF(1)
- Line Input #1, itxt
- wtxt = wtxt & itxt & vbTab
- Loop
- Close #1
- arr = Split(Trim(wtxt), vbTab)
- n = UBound(arr) ': MsgBox n
- j = 1: k = 1
- For i = 1 To n - 1
- If i <> 1 And (i - 1) Mod 6 = 0 Then j = j + 1
- If j > Sheets.Count Then
- Worksheets(j - 1).Copy after:=Worksheets(Worksheets.Count)
- With ActiveSheet
- .Name = j: .Range("d7:f7") = "": .Range("d32:f32") = "": .Range("d57:f57") = ""
- End With
- End If
- shname = CStr(j)
- If i Mod 2 = 1 Then
- txt1 = arr(i - 1) & vbTab & arr(i) & vbTab & arr(i)
- If k = 1 Then
- Sheets(shname).[d7].Resize(1, 3) = Split(txt1, vbTab): txt1 = ""
- End If
- If k = 2 Then
- Sheets(shname).[d32].Resize(1, 3) = Split(txt1, vbTab): txt1 = ""
- End If
- If k = 3 Then
- Sheets(shname).[d57].Resize(1, 3) = Split(txt1, vbTab): txt1 = ""
- End If
- k = k + 1: If k > 3 Then k = 1
- End If
- Next
- Application.ScreenUpdating = True
- MsgBox "共 " & Int(i / 2) & " 条数据,成功填入 " & Sheets.Count & " 张表"
- End Sub
复制代码
请测试 |
|