|
Option Explicit
Const START = 4 '开始行
Sub test1()
Dim arr, i
arr = [a1].CurrentRegion.Offset(1)
Open ThisWorkbook.Path & "\" & arr(START, 1) & ".txt" For Output As #1
For i = START To UBound(arr, 1) - 1
Print #1, arr(i, 2) & ";" & arr(i, 3)
If arr(i, 1) <> arr(i + 1, 1) Then
Close #1
If Len(arr(i + 1, 1)) Then Open ThisWorkbook.Path & "\" & arr(i + 1, 1) & ".txt" For Output As #1
End If
Next
End Sub
'或者==================================
Option Explicit
Const START = 4, NUM = 10 '每个站点的开始行、取连续数据个数
Sub test1()
Dim arr, i, cnt
arr = [a1].CurrentRegion.Offset(1)
Open ThisWorkbook.Path & "\" & arr(1, 1) & ".txt" For Output As #1
For i = 1 To UBound(arr, 1) - 1
cnt = cnt + 1
If cnt >= START And cnt - START < NUM Then
Print #1, arr(i, 2) & ";" & arr(i, 3)
End If
If arr(i, 1) <> arr(i + 1, 1) Then
Close #1: cnt = 0
If Len(arr(i + 1, 1)) Then Open ThisWorkbook.Path & "\" & arr(i + 1, 1) & ".txt" For Output As #1
End If
Next
End Sub |
评分
-
1
查看全部评分
-
|