Hi,
I'm a beginner in VBA and I'm trying to extract different numbers which will always occur after a specific phrase in the string.
The string looks like below (but can vary according to the products that are bought). It's a list of products that has been bought by a client with quantities before.
Ex : the client has bought 65 gazons en rouleaux, 1 engrais entretien, 1 engrais starter
65x Gazon en rouleaux(id:1) | 1x Engrais d'entretien Sac jusqu'à 200m²(id:5) | 1x Engrais starter Sac jusqu'à 80m²(id:4)
I would like to have a column for each product and only the quantity.
The length of the numbers will vary.
The list of products as well. That's why I can't do a split and the macro needs to find the specific text in the string to extract the right number and place it inthe right column.
For instance, we can have cells like below :
Only 2 products bought
34x Gazon en rouleaux(id:1) | 1x Engrais starter Sac jusqu'à 80m²(id:4)
Only 1 product bought
350x Gazon en rouleaux(id:1)
I've tried to use several macro found on the web but they didn't match my exact request and I was unable to customize them as I'm too beginner.
Below one of the macro that seemed to address my need.
Sub GetPrice()
Dim sExpression As String
Dim sPhrase As String
Dim LenPhrase As Long
Dim NumStart As Long
Dim NumLen As Long
sExpression = "19 apples with price of $0.30 and use by date of 31 July 2016"
sPhrase = "price of"
LenPhrase = Len(sPhrase)
NumStart = InStr(sExpression, sPhrase) + LenPhrase + 1
NumLen = InStr(Right(sExpression, Len(sExpression) - NumStart), " ")
Debug.Print Mid(sExpression, NumStart, NumLen)
End Sub
Thank you very much for your help.
Gabbi
I'm a beginner in VBA and I'm trying to extract different numbers which will always occur after a specific phrase in the string.
The string looks like below (but can vary according to the products that are bought). It's a list of products that has been bought by a client with quantities before.
Ex : the client has bought 65 gazons en rouleaux, 1 engrais entretien, 1 engrais starter
65x Gazon en rouleaux(id:1) | 1x Engrais d'entretien Sac jusqu'à 200m²(id:5) | 1x Engrais starter Sac jusqu'à 80m²(id:4)
I would like to have a column for each product and only the quantity.
The length of the numbers will vary.
The list of products as well. That's why I can't do a split and the macro needs to find the specific text in the string to extract the right number and place it inthe right column.
For instance, we can have cells like below :
Only 2 products bought
34x Gazon en rouleaux(id:1) | 1x Engrais starter Sac jusqu'à 80m²(id:4)
Only 1 product bought
350x Gazon en rouleaux(id:1)
I've tried to use several macro found on the web but they didn't match my exact request and I was unable to customize them as I'm too beginner.
Below one of the macro that seemed to address my need.
Sub GetPrice()
Dim sExpression As String
Dim sPhrase As String
Dim LenPhrase As Long
Dim NumStart As Long
Dim NumLen As Long
sExpression = "19 apples with price of $0.30 and use by date of 31 July 2016"
sPhrase = "price of"
LenPhrase = Len(sPhrase)
NumStart = InStr(sExpression, sPhrase) + LenPhrase + 1
NumLen = InStr(Right(sExpression, Len(sExpression) - NumStart), " ")
Debug.Print Mid(sExpression, NumStart, NumLen)
End Sub
Thank you very much for your help.
Gabbi