Alternative.
This will read the data directly from cvs file.
Sub test()
Dim fn As String, txt As String, w, x, y
Dim i As Long, ii As Long, ub As Long, flg As Boolean
fn = Application.GetOpenFilename("CSVFiles,*.csv")
If fn = "False" Then Exit Sub
txt = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).REadAll
x = Split(txt, vbCr): ub = UBound(Split(x(0), ","))
With CreateObject("VBScript.RegExp")
For i = 0 To UBound(x)
y = Split(x(i), ",")
.Pattern = "^([^,\[]+),+$"
If .test(x(i)) Then
If IsEmpty(w) Then
ReDim w(1 To ub + 100, 1 To 1)
Else
ReDim Preserve w(1 To UBound(w, 1), 1 To UBound(w, 2) + 1)
End If
w(1, UBound(w, 2)) = .Execute(x(i))(0).submatches(0): flg = False
End If
.Pattern = "^(\[\d+\]).*"
If .test(x(i)) Then
If flg Then ReDim Preserve w(1 To UBound(w, 1), 1 To UBound(w, 2) + 1)
w(2, UBound(w, 2)) = .Execute(x(i))(0).submatches(0): flg = True
End If
.Pattern = "^(-?\d+(\.\d+)?,?)+.*"
If .test(x(i)) Then
For ii = 0 To UBound(y)
w(ii + 3, UBound(w, 2)) = y(ii)
Next
End If
Next
End With
Sheets("sheet1").Cells(1).Resize(UBound(w, 1), UBound(w, 2)).Value = w
End Sub
Bookmarks