Wednesday, February 28, 2018

Regex in Vba excel




Can anyone provide the regex for extracting the data between the 2nd and the 3rd "|"



For example, for the below data



2016 Annual | 1.1 - 12.31 | COH (NP) | #21485



The result should be
COH (NP)



Answer



A regex is overkill for this. Just split on "|" and take the desired component:



Sub test()
Dim S As String
S = "2016 Annual | 1.1 - 12.31 | COH (NP) | #21485"
Debug.Print Split(S, "|")(2) 'prints COH (NP)
End Sub

No comments:

Post a Comment