简体   繁体   中英

Excel VBA extract price after specific word

I need to scrape item price from Amazon page. Using VBA code Htmldoc.GetElementById("price") I get this output:

RRP:£36.00 Price:£25.00 (£35.71 / l) & FREE Delivery. Delivery Details You Save:£11.00 (31%)

But is there a way to extract only price which is 25.00 in this example? I know how to do it with FIND formula by key word 'Price:' if text posted to cell, but in this case it has to be done in VBA only.

Any help is much appreciated.

You can use split like that

Sub Test()
    Dim s As String
    s = "RRP:£36.00 Price:£25.00 (£35.71 / l) & FREE Delivery . Delivery Details You Save:£11.00 (31%)"
    Debug.Print "Price = " & Split(Split(s, "Price:")(1))(0)
End Sub

As you probably wish the numeric price, you can use Val :

PriceInfo = "RRP:£36.00 Price:£25.95 (£35.71 / l) & FREE Delivery . Delivery Details You Save:£11.00 (31%)"
Price = Val(Split(PriceInfo, "Price:£")(1))
? Price 
 25.95 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM