我有这个csv文件,我想组织成一个结构。我正在测量一些表面,并且在每个表面下都有部分,并且在每个部分下面都有许多运行。我想从第一个表面提取每个元素直到下一个表面,依此类推,直到根据数据中出现的表面数量对数据进行分组。我想编写一个通用代码来解析将要进行的测量数据。现在,我的表面代码只能存储每个表面下的最后一个元素,并告诉我“下标超出范围。我堆叠了,我需要帮助。下面是数据和代码到目前为止。谢谢
SURFACE
SECTION
RUN
-0.07764007
0.07762
42
0.07801
-0.07747896
0.07744
-0.07753022
0.07759
-0.07729586
0.07747
-0.07753753
0.07741
-0.07742768
RUN
-0.077435
0.07747
-0.07757416
0.07726
-0.07761077
0.07756
-0.07750092
-57
-0.07712009
0.07771
-0.07769133
0.07769
-0.07713472
0.07733
-0.07726657
0.0774
-0.07731783
0.07743
-0.07754486
0.07752
-0.07755219
0.07745
-0.07723726
SECTION
RUN
-0.07785247
0.07765
-0.07742036
-0.0776
-0.07742036
0.07747
-0.07729586
0.07741
-0.07744966
0.07724
-0.07753753
0.0773
-0.07747896
0.07759
-0.07746429
0.07771
SURFACE
SECTION
RUN
-0.07753753
0.07786
-0.07729586
0.07743
-0.07762542
0.07763
-0.07723726
0.07735
-0.077955
-71
-0.07681249
0.07727
-0.0775229
0.07733
-0.07747896
0.07738
-0.07714205
0.07746
-0.07737642
0.07744
-0.07761809
0.07727
-0.07755951
0.07754
-0.07792571
代码
Sub report()
Dim FilePath As String, LineFromFile As Variant, LineItems As Variant
Dim SURF() As Variant
Dim surface As String, Section As String, run As String
Dim DATA() As Variant, counter_surf As Long, counter_sect As Long
Dim Snumbs() As Variant, j As Long, S As Integer, i As Long, q As Long
Dim n As Long, m As Long, counter As Long
Dim Endoffileflag As Boolean, errorflag As Boolean
surface = "SURFACE"
Section = "SECTION"
run = "RUN"
counter = 0
counter_surf = 0
counter_sect = 0
counter_run = 0
Endoffileflag = False
errorflag = False
FilePath = Application.GetOpenFilename("Cvv Files (*.csv), *.csv")
Open FilePath For Input As #1
Do Until EOF(1)
Line Input #1, LineFromFile
LineItems = Split(LineFromFile, ",")
For i = LBound(LineItems) To UBound(LineItems)
ReDim Preserve DATA(i)
DATA(i) = Mid(LineItems(i), 2, Len(LineItems(i)) - 2)
If DATA(i) <> surface And DATA(i) <> Section And DATA(i) <> run Then
DATA(i) = CDbl(DATA(i))
End If
ActiveCell.Offset(i).Value = DATA(i)
Next i
Loop
'For j = LBound(DATA) To UBound(DATA)
Do
If DATA(counter) = surface Then
ReDim Preserve SURF(counter_surf)
'If DATA(j + 1) <> surface Then
Do
SURF(counter_surf) = DATA(counter)
counter = counter + 1
Loop Until DATA(counter) = surface And counter <= UBound(DATA)
'End If
'counter = counter + 1
End If
counter_surf = counter_surf + 1
Loop Until counter >= UBound(DATA)
'Next j
Close #1
End Sub