I have no coding background but have always been curious to try it out. I've been enjoying it so far but have recently been stumped. I have exhausted my limited understanding and research on trying to figure this out, so any help is much appreciated!
My function takes a string and creates it into an array. Then I search the array for specific strings and output them as a number and a date. I have successfully made it this far but cannot figure out how to have VBA return these results in two columns on the spreadsheet. It seems to only give me the last result of the For function.
Here is the code using Excel 2016 and 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
Here is what I'm getting when I use the function on a spreadsheet:
test = price1 & " " & date1