我没有编码背景,但一直很想尝试一下。到目前为止我一直很享受,但最近被难住了。我已经用尽了我有限的理解和研究来试图解决这个问题,所以非常感谢任何帮助!
我的函数接受一个字符串并将其创建为一个数组。然后我在数组中搜索特定字符串并将它们输出为数字和日期。我已经成功做到了这一点,但无法弄清楚如何让 VBA 在电子表格的两列中返回这些结果。它似乎只给了我 For 函数的最后一个结果。
这是使用 Excel 2016 和 VBA 的代码:
Function test() As Variant
Dim data As String: data = "push.29Sep17 and 333>! push.28Sep17 and 55555>! push.27Sep17 and 4444>!"
Dim day() As String: day() = Split(data, "!")
Dim num As Integer: num = UBound(day) - 1
For i = 0 To num
Dim p1 As Integer: p1 = InStr(1, day(i), "and ")
Dim p2 As Integer: p2 = InStr(p1, day(i), ">")
Dim p3 As Integer: p3 = p1 + 4
Dim p4 As Integer: p4 = p2 - p3
Dim price1 As String: price1 = Mid(day(i), p3, p4)
Dim d1 As Integer: d1 = InStr(1, day(i), "push.")
Dim d2 As Integer: d2 = d1 + 5
Dim date1 As String: date1 = Mid(day(i), d2, 7)
test = price1 & " " & date1
Debug.Print price1, date1
Next i
End Function