Slava Dolkart
Slava Dolkart

Reputation: 67

VBA checking multiple html checkboxes on web

The goal is to check multiple checkboxes depends on data in cell J(i) that is seperated with delimiter "|".

Example: Column J, Row (i) = SkillA|SkillB|SkillC

Checkbox: check/click this 3 skills.

At the moment I am able to select only 1 checkbox by storing only 1 id in cell J:

Cell J = SkillA

Doc.getElementById(sht.Range("J" & i)).Click

Full code:

    Dim sht As Worksheet
    Set sht = ThisWorkbook.Sheets("Fields")
    Dim LastRow As Long
    Dim i As Long
    LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
    Dim IE As Object
    Dim Doc As HTMLDocument
    Set IE = CreateObject("InternetExplorer.Application")
    '--------------------------------
    For i = 2 To LastRow
    IE.Visible = True
    IE.navigate sht.Range("A" & i).Value
    Do While IE.Busy
    Application.Wait DateAdd("s", 1, Now)
    Loop
    Set Doc = IE.document
code....
code....
     Doc.getElementById("tab6").Click
     Doc.getElementById(sht.Range("J" & i)).Click

    Next i
    IE.Quit
    MsgBox "Process 100% completed"
    End Sub

Upvotes: 0

Views: 192

Answers (1)

QHarr
QHarr

Reputation: 84465

A little confusing but sounds like you want to use split to generate an array of values you can pass as id values for checkboxes

Dim values() As String, i As Long
values = Split(sht.Range("J" & i).Value, "|")

For i = LBound(values) To UBound(values)
    On Error Resume Next
    Doc.getElementById(values(i)).Click
    On Error GoTo 0
Next

Upvotes: 1

Related Questions