How would I extract the nth element from a VBA string array?
I have a string, like: TEST - 2017/01/20 = Invoice
I wish to extract out the 2nd and 3rd elements as concisely as possible. I was trying something Javascripty like this, which doesn't work, so there must be a VBA way:
Dim Report As String
Dim CurrLine As String
Dim CurrDate As String
Dim CurrTask As String
CurrLine = "TEST - 2017/01/20 = Invoice"
CurrDate = Trim(Split(CurrLine, '-')[1])
CurrTask = Trim(Split(CurrLine, '=')[1])
Report = Report & CHR(34) & CurrDate & CHR(34) & "," & CHR(34) & CurrTask & CHR(34)
//result: "2017/01/20","Invoice"
a possible solution
Dim Report As String
Dim CurrLine As String
Dim CurrDate As String
Dim CurrTask As String, St
CurrLine = "TEST - 2017/01/20 = Invoice"
St=Split(replace(CurrLine, "=","-"),"-")
CurrDate = St(1)
CurrTask = St(2)
Report = Report & CHR(34) & CurrDate & CHR(34) & "," & CHR(34) & CurrTask & CHR(34) //result: "2017/01/20","Invoice"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With