Results 1 to 3 of 3

Thread: VBA to get a number for a HTML style value without the "%" suffix

  1. #1
    Board Regular smide's Avatar
    Join Date
    Dec 2015
    Posts
    151
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA to get a number for a HTML style value without the "%" suffix

    Hello.


    In cell A1 (Sheet 1) I'm receiving a huge HTML code. I need to extract somehow values for 'top' and 'left' without % suffix.


    for: style="top: 54%; left: 13%; I need only 54 and 13


    Results should be placed in column B for top values (B2:B300) and column C for left values (C2:C300).




    example.


    HTML in cell A1: style="top: 69%; left: 8%; background-color: rgb(0, 255, 255); style="top: 3%; left: 61%;....


    Results after macro run (Sheet 1):


    A B C
    1 style="top: 69%; left: 8%; background-color: rgb(0, 255, 255); style="top: 3%; left: 61%;.... Top Left
    2 69 8
    3 3 61
    4 .... ....
    5 .... ....

  2. #2
    MrExcel MVP
    Join Date
    Jan 2008
    Posts
    14,837
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    12 Thread(s)

    Default Re: VBA to get a number for a HTML style value without the "%" suffix

    Try this for results starting "B2".
    Code:
    Sub MG06Sep24
    Dim txt As String, Sp As Variant, n As Long, c As Long, a, b
    txt = Replace(Range("A1"), ";", ":")
    Sp = Split(txt, ":")
    a = 1: b = 1
    For n = 0 To UBound(Sp)
        If Sp(n) Like "*top" Then
            a = a + 1
            With Cells(a, "B")
                .Value = Trim(Sp(n + 1))
                .NumberFormat = "general"
                .Value = .Value * 100
            End With
        ElseIf Sp(n) Like "*left" Then
             b = b + 1
            With Cells(b, "C")
                .Value = Trim(Sp(n + 1))
                .NumberFormat = "general"
                .Value = .Value * 100
            End With
        End If
    Next n
    End Sub
    Regards Mick

  3. #3
    Board Regular WaterGypsy's Avatar
    Join Date
    Jan 2010
    Location
    London, England
    Posts
    697
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Default Re: VBA to get a number for a HTML style value without the "%" suffix

    You could start with something like this:

    Code:
    Sub Test1()
     
    Dim temp
    Dim ssTop As String
    Dim sLeft As String
    ssTop = ""
    sLeft = ""
     
    temp = Split(Range("A1").Value, " ")
    For i = 0 To UBound(temp)
        If InStr(temp(i), "top") Then
            
            ssTop = Left(temp(i + 1), Len(temp(i + 1)) - 2)
            
        End If
        If InStr(temp(i), "left") Then
            sLeft = Left(temp(i + 1), Len(temp(i + 1)) - 2)
        End If
        
    If ssTop <> "" And sLeft <> "" Then
     
        MsgBox ssTop & " " & sLeft
        ssTop = ""
        sLeft = ""
    End If
    
     Next i
     
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •