我有一个包含如下字符串的集合:
130each 09/01/2017 09/01/2017
12each 09/01/2017 09/01/2017
1each 09/01/2017 09/01/2017
我通过以下代码获取这些值:
Dim col as New Collection
For i = 1 To lastRow
If InStr(ws1.Cells(i, 1), "each")
col.Add ws1.Cells(i, 1)
End If
Next i
现在我想在第一个空格后分隔字符串,并将每个部分存储在两个单独的集合中。示例第二个集合和第三个集合应包含以下内容:
130each [at index 0 of col2]
09/01/2017 09/01/2017 [at index 0 of col3]
12each [at index 1 of col2]
10/11/2017 10/11/2017 [at index 1 of col3]
...so on
关于如何处理这个问题的任何想法我知道我将循环使用该集合但是在第一个空格之后我将如何分成两个单独的集合?
答案 0 :(得分:1)
这样的事情:
Dim col2 As New Collection
Dim col3 As New Collection
Dim x As Variant
For Each x In col
Dim parts As Variant
parts = Split(x, " ", 2)
col2.Add parts(0)
col3.Add parts(1)
Next