Variable within Element ID

ian0886

New Member
Joined
Dec 10, 2016
Messages
42
Hi Guys,

I'm doing a code to create multiple accounts using FB as an example.
i'm having issues selecting the gender from the page.

If in the cell the sex is female and corresponds to u_1_4, typing this in the code would work.
Looking at the highlighted part in red, i'll like the formula to be more flexible to select the gender based on my excel sheet.
is there a way out of this?

HTML:
<label class="_58mt" for="u_1_4">Female</label>
<input name="sex" class="_8esa" id="u_1_4" type="radio" value="1">

VBA Code:
Private Sub insert1()
    Dim ie As Object, doc As HTMLDocument
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.Visible = True
    ie.Navigate "https://www.facebook.com/"

    Do While ie.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
    
    Set doc = ie.Document
    
    doc.getElementById("u_0_2").Click
    
    Dim counter, maxrow As Integer, sex As Range
    maxrow = Range("a1").CurrentRegion.Rows.count
    gender[COLOR=rgb(209, 72, 65)][B] = Sheets("Data").Range("h" & counter + 1).Value[/B][/COLOR]
    For counter = 1 To maxrow
    
    doc.getElementById("u_1_b").Value = Sheets("Data").Range("a" & counter + 1).Value
    doc.getElementById("u_1_d").Value = Sheets("Data").Range("b" & counter + 1).Value
    doc.getElementById("u_1_g").Value = Sheets("Data").Range("c" & counter + 1).Value
    doc.getElementById("u_1_l").Value = Sheets("Data").Range("d" & counter + 1).Value
  
    doc.getElementById("day").Value = Sheets("Data").Range("e" & counter + 1).Value
    doc.getElementById("month").Value = Sheets("Data").Range("f" & counter + 1).Value
    doc.getElementById("year").Value = Sheets("Data").Range("h" & counter + 1).Value
   [B][COLOR=rgb(184, 49, 47)] doc.getElementById("gender").Click[/COLOR][/B]
    Next
    
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top