Hi
I am trying to extract a number which will always occur after a specific phrase in a string.
As the length of the number will vary, ideally I want the code to simply search for the space occurring after the number and then determine that the number must lie between the end of the specific phrase and the space.
I tried to use RegExp, without success.
I am reverting to Mid, Instr and Len:
Sub GetPrice()
Dim sExpression As String
Dim sPhrase As String
sExpression = "19 apples with price of $0.30 and use by date of 31 July 2016"
sPhrase = "price of"
Debug.Print Mid(sExpression, InStr(sExpression, sPhrase) + Len(sPhrase) + 1, 5)
End Sub
The '5' is want I want the code to automatically detect.
Any help as always greatly appreciated.
Cheers
pvr928
I am trying to extract a number which will always occur after a specific phrase in a string.
As the length of the number will vary, ideally I want the code to simply search for the space occurring after the number and then determine that the number must lie between the end of the specific phrase and the space.
I tried to use RegExp, without success.
I am reverting to Mid, Instr and Len:
Sub GetPrice()
Dim sExpression As String
Dim sPhrase As String
sExpression = "19 apples with price of $0.30 and use by date of 31 July 2016"
sPhrase = "price of"
Debug.Print Mid(sExpression, InStr(sExpression, sPhrase) + Len(sPhrase) + 1, 5)
End Sub
The '5' is want I want the code to automatically detect.
Any help as always greatly appreciated.
Cheers
pvr928