0

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 

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

9 Comments

1 thing is still not exactly as I wanted to - I would like to use the values as names (SkillA|SkillB|SkillC etc) but at the moemnet only Id works (ID1|ID2|ID3). Here an example of the element: <input name="role" id="chkID1" onclick="somethinghappens" type="checkbox" features="ACM|"> <label id="lblID1" for="chkID1">SkillA</label>
You are using getElementById so only valid ids will work. If you want a method to use to select by name attribute this will in part depend on how many with any given name you have? Is there only ever one attribute on the page with a given name?
There are 337 unique ID with Unique names per ID, In the future might be 500 & 1000 id's / names.
And you want to select a checkbox based on name? Doc.querySelector("[name='yourNameValueGoesHere']").click .Try that. If doesn't work please post a new question and I will have a look at it there.
Yes, after the elemnt "for="chkID1" the is a name > SkillA </label>. How do I make it take "SkillA" instead of the "chkID1"? idialy SkillA|SkillB|SkillC will be stored in column J
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.