Merge multiple cells into one merged cell with line spacing - excel

I was working on an excel template to make quotes. This template has a list of materials which you can validate so that a quote is automatically generated.
In itself, the template works fine, the problem appears when I try to add a new function, which will allow you through "UserForm" to insert a new item to the list.
Before this function, I was using the "=CONCATENATE" command to drag several items from the list to the final quote and added a "CHARACTER(10)" so that there is a line spacing between each item because it must appear in unified cells so that then the command "=SHEARCHV" returns all the items. When trying to automate this process, I realize that when I add a new row to the list, it is not added to the list of "=CONCATENATE" so, even though it works in the total sum, the specific item never appears in the description of the items in the final quote.
here some captures
First Step: Check whatever item you want to add
Second Step: The item will move to another sheet to add taxes and prorate as well as labor
Third Step: After that I should send the items that are separated in a single cell and with a space between each one so that finally the function "=SHEARCHV" looks for the "Server Room" and returns me the description of the items like the next image
In the yellow format you can see how the template worked before adding this new function
What I want to do is that when adding a new item to the list I also add a function which can insert several cells in a combined multiple cells, so that there is a line spacing between each item
Main lenguaje: Spanish
Excel Download: https://drive.google.com/file/d/1xUxd7Ze6AB25MVfyxlY9dSlWUeQBTDCH/view?usp=sharing
VBA CODE TO ENTER NEW ITEM
Sheets("PREVISTA").Range("A25").EntireRow.Insert
Sheets("PRORRATEO").Range("A48").EntireRow.Insert
Sheets("HOJA DE DATOS").Range("A22").EntireRow.Insert
Sheets("HOJA DE DATOS").Range("A22") = 1
Sheets("HOJA DE DATOS").Range("C22") = 1
Sheets("HOJA DE DATOS").Range("B22") = TextBox1
Sheets("HOJA DE DATOS").Range("G22") = TextBox2
Sheets("HOJA DE DATOS").Range("E22") = "=G22*'DATOS DE INTERNET'!C2"
Sheets("HOJA DE DATOS").Range("H22") = "=G22*C22"
Sheets("HOJA DE DATOS").Range("I22") = "=G22*$I$2"
Sheets("HOJA DE DATOS").Range("J22") = "=G22*$J$2"
Sheets("HOJA DE DATOS").Range("K22") = "=G22*$K$2"
Sheets("HOJA DE DATOS").Range("L22") = "=(K22+J22+I22)*$L$2"
Sheets("HOJA DE DATOS").Range("M22") = "=(I22+J22+K22+L22)*C22"
Sheets("HOJA DE DATOS").Range("N22") = "=H22+M22"
Sheets("PRORRATEO").Range("C47").Copy: Sheets("PRORRATEO").Range("C48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("V47").Copy: Sheets("PRORRATEO").Range("V48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("X47").Copy: Sheets("PRORRATEO").Range("X48").PasteSpecial xlPasteAll
Sheets("PRORRATEO").Range("F48") = "=C48/$C$2"
Sheets("PRORRATEO").Range("G48") = "=F48*$D$17"
Sheets("PRORRATEO").Range("I48") = "=G48/($C$20+$C$3)"
Sheets("PRORRATEO").Range("J48") = "=I48*$F$9"
Sheets("PRORRATEO").Range("K48") = "=J48+G48"
Sheets("PRORRATEO").Range("O48") = "=N48+M48+L48+K48"
Sheets("PRORRATEO").Range("B48") = "=CONCATENAR(X48)"
If CheckBox1.Value = True Then
Sheets("PRORRATEO").Range("L48") = "=K48*L24"
ElseIf CheckBox2.Value = True Then
Sheets("PRORRATEO").Range("M48") = "=K48*M24"
ElseIf CheckBox3.Value = True Then
Sheets("PRORRATEO").Range("N48") = "=K48*N24"
Else
Sheets("PRORRATEO").Range("N48") = "=K48*N24"
End If
Sheets("PRORRATEO").Range("Q48") = "=O48/O5"
Sheets("PRORRATEO").Range("R48") = "=Q48*O6"
Sheets("PREVISTA").Range("C24").Copy: Sheets("PREVISTA").Range("C25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("N24").Copy: Sheets("PREVISTA").Range("N25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("P24").Copy: Sheets("PREVISTA").Range("P25").PasteSpecial xlPasteAll
Sheets("PREVISTA").Range("B12") = "=CONCATENAR(P12:P26)"
End If
End Sub ```
I hope I have expressed myself well, any help is welcome thanks

Related

update data via macro from another workbook

I need some help with vba code. I'm self-lerning so please be understanding for simply cases ;)
I'm trying to create macro which will be looking for some records/cells in one workbook (FileA) (determined by 3 conditions) and then paste values to another workbook (FileB) and after that find in another tab in FileB some values where condition will be pasted value to match them with looking value (I belivie it could be done somehow with Vlookup but I get stuck).
Below problematic for me part of code (I'm working on some files found in work, no one use it now).
First issue is with Set Update, I don't know why it takes it as "Nothing"... conditions are true - I mean "pp1" is existing in column A in FileA.
Second issue shows when I change i start range to some "later" numbers, eg From i = 2280, macro is ignoring last line where should assign some values (again shows update2 as "nothing") but value if pp2 is existing in W column in tab data...
Dim name As String
name = "[path to file on sharepoint]"
Application.ScreenUpdating = False
Workbooks.Open Filename:=name
a = 1
For i = 2263 To 14000
If Workbooks("FileA").Sheets("Main").Cells(i, 11) = "CANCEL" And Workbooks("FileA").Sheets("Main").Cells(i, 6) = "DENIS" And Workbooks("FileA").Sheets("Main").Cells(i, 5) > 1301358454 Then
pp1 = Workbooks("FileA").Sheets("Main").Cells(i, 1)
If pp1 > 0 Then
Set Update = Workbooks("FileA").Worksheets("Main").Range("A:A").Find(pp1, lookat:=xlPart)
If Update > 0 Then
Update = Update.Row
Workbooks("FileB").Worksheets("lost").Cells(a, 1).Value = Workbooks("FileA").Worksheets("Main").Cells(Update, 5)
pp2 = Workbooks("FileB").Worksheets("lost").Cells(a, 1)
update2 = Workbooks("FileB").Worksheets("data").Range("W:W").Find(pp2, lookat:=xlPart).Row
Workbooks("FileB").Worksheets("lost").Cells(a, 5) = Workbooks("FileB").Worksheets("data").Cells(update2, 43)

Clear ComboBox Containig an Array VBA and Repopulate with Column Index

I have a sigle column ComboBox that I have populated with a dynamic array; however, I'd like the code to replace the value of the combo box with respective column from my ListBox.
'Prepares the Active Escorts list box.
ivb = 0
i = 0
With frmEntry
.listboxActiveEscorts.Clear
.listboxActiveEscorts.ColumnHeads = False
.listboxActiveEscorts.ColumnCount = "15"
.listboxActiveEscorts.ColumnWidths = "0,100,100,0,0,100,100,0,0,0,0,0,100,100,80"
i = 0
'Badge # combobox properties
ReDim vbArray(0 To vbArrayCount - 1)
For i = 0 To vbArrayCount - 1
ivb = ivb + 1
vbArray(ivb - 1) = loVisBadge.Range.Cells(i + 2, 1).Value
Next i
.cbxVisitorBadgeNumber.List = vbArray
End With
This population of the ComboBox executes beautifully, in my belief, but if you see a better way to implement the dynamic list, I'm all ears.
I have a button that I will use to reset the form, which also works for the most part. When an item is selected from the list, I am able to clear all controls except for the ComboxBox containing the array of values. I will be adding two additional arrays to each of the other ComboBoxes on the form, and I imagine I am going to have the same problem: "Could not set the value property. Invalid property value"
This is the code assigned to click event of the ListBox:
Private Sub listboxActiveEscorts_Click()
With frmEntry
.cbxEscortSelectName.Value = .listboxActiveEscorts.Column(1) + " " + .listboxActiveEscorts.Column(2)
.txtCredential.Value = .listboxActiveEscorts.Column(4)
.txtEscortCompany.Value = .listboxActiveEscorts.Column(3)
.cbxVisitorName.Value = .listboxActiveEscorts.Column(5) + " " + .listboxActiveEscorts.Column(6)
.txtVECompany.Value = .listboxActiveEscorts.Column(7)
.txtVEDOB.Value = .listboxActiveEscorts.Column(8)
.txtVEIdentification.Value = .listboxActiveEscorts.Column(9)
.txtVEIDNumber.Value = .listboxActiveEscorts.Column(10)
.txtVEExpirationDate.Value = .listboxActiveEscorts.Column(11)
.txtVEStart.Value = .listboxActiveEscorts.Column(12)
.txtVEEnd.Value = .listboxActiveEscorts.Column(13)
'.cbxVisitorBadgeNumber.Value = ""
.cbxVisitorBadgeNumber = vbNullString
.cbxVisitorBadgeNumber.Value = .listboxActiveEscorts.Column(14)
End With
End Sub
What am I missing here. I tried to ReDim the array that assigned the values, but that didn't work. Is it a data type thing, perhaps?
In the picture below, you'll see the values populated in the controls, all except the visitor badge # (ComboBox which throws the error...I have commented out the line for illustration purposes, so you'll see the visitor badge # is blank).

How to use Autofill/Filldown with a range of values

I have been trying to get Excel to apply a formula over a set of columns and then extend the pattern across the entire set of rows.
This has led to the following code:
For i = 0 To avgsheetNames.Count - 1
If Contains(CStr(avgsheetNames(i)), "Scores") = True Then
With mainWorkBook.Worksheets(avgsheetNames(i))
strFormulas(1) = "=SUM(Aggregated_Internal_Scores!I2:I7)/6"
strFormulas(2) = "=SUM(Aggregated_Internal_Scores!J2:J7)/6"
strFormulas(3) = "=SUM(Aggregated_Internal_Scores!K2:K7)/6"
strFormulas(4) = "=SUM(Aggregated_Internal_Scores!L2:L7)/6"
strFormulas(5) = "=SUM(Aggregated_Internal_Scores!M2:M7)/6"
strFormulas(6) = "=SUM(Aggregated_Internal_Scores!N2:N7)/6"
strFormulas2(1) = "=SUM(Aggregated_Internal_Scores!I8:I13)/6"
strFormulas2(2) = "=SUM(Aggregated_Internal_Scores!J8:J13)/6"
strFormulas2(3) = "=SUM(Aggregated_Internal_Scores!K8:K13)/6"
strFormulas2(4) = "=SUM(Aggregated_Internal_Scores!L8:L13)/6"
strFormulas2(5) = "=SUM(Aggregated_Internal_Scores!M8:M13)/6"
strFormulas2(6) = "=SUM(Aggregated_Internal_Scores!N8:N13)/6"
mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H2").Formula = strFormulas
mainWorkBook.Worksheets(avgsheetNames(i)).Range("C3:H3").Formula = strFormulas2
mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H3").AutoFill Destination:=mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32")
End With
End If
As you can see I have tried to provide the pattern I am going for where the values extracted from the "Aggregated_Internal_Scores" sheet should follow the pattern I2:I7 > I8:I13 > I14:I19 and so on.
However, when the macro has been executed what I get is I2:I7 > I8:I13 > I4:I9 > I10:I15?
It seems Excel is taking the block C2:H3 as the pattern and just incrementing by 2 at the start of every block.
Can you anyone explain where I have gone wrong and how I can specify that I want the extraction of sheet values to follow a certain pattern?
Thank you in advance!
Use:
mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32").Formula = "=SUM(INDEX(Aggregated_Internal_Scores!I:I,(ROW($ZZ1)-1)*6+2):INDEX(Aggregated_Internal_Scores!I:I,(ROW($ZZ1)-1)*6+7))/6"
Replace everything inside the If with that.
If one has Office 365 with dynamic array formula then use:
mainWorkBook.Worksheets(avgsheetNames(i)).Range("C2:H32").Formula2 = "=SUM(INDEX(Aggregated_Internal_Scores!I:I,SEQUENCE(6,,(ROW($ZZ1)-1)*6+2))/6"

Save SM37 rows with sorting via GUI Script?

The following SAP GUI Script for SAP 740 saves the SM37 list to a text file.
Before saving the list, I'd like to sort the list by Start date and Start time.
I can display the popup to select Sort fields. On left side there is a table control with current Sort columns (job name, created by, progress, scheduled start date, scheduled start time), on right side there is a table control with all possible Sort columns, each of these left and right Sort columns can be selected, and between the two table controls there are buttons to move Sort columns from left to right or vice versa.
Now, to select Sort columns, I have to select rows of table controls, but I don't know how to do it. Can you help me?
Public Sub RunSM37Cancelled()
Dim W_Ret As Boolean
W_Ret = Attach_Session
If Not W_Ret Then
Exit Sub
End If
On Error GoTo disperr
objSess.findById("wnd[0]").maximize
objSess.findById("wnd[0]/tbar[0]/okcd").Text = "sm37"
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/usr/txtBTCH2170-JOBNAME").Text = "*"
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/usr/txtBTCH2170-USERNAME").Text = "*"
objSess.findById("wnd[0]/usr/txtBTCH2170-USERNAME").SetFocus
objSess.findById("wnd[0]/usr/txtBTCH2170-USERNAME").caretPosition = 1
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/usr/chkBTCH2170-SCHEDUL").Selected = False
objSess.findById("wnd[0]/usr/chkBTCH2170-READY").Selected = False
objSess.findById("wnd[0]/usr/chkBTCH2170-RUNNING").Selected = False
objSess.findById("wnd[0]/usr/chkBTCH2170-FINISHED").Selected = False
objSess.findById("wnd[0]/usr/chkBTCH2170-ABORTED").Selected = True
objSess.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").Text = Format(Now()-1,"mm/dd/yyyy")
objSess.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").SetFocus
objSess.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").caretPosition = 10
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").Text = Format(Now(), "mm/dd/yyyy")
objSess.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").SetFocus
objSess.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").caretPosition = 10
objSess.findById("wnd[0]").sendVKey 0
objSess.findById("wnd[0]/tbar[1]/btn[8]").press
objSess.findById("wnd[0]/usr/lbl[80,10]").SetFocus
objSess.findById("wnd[0]/usr/lbl[80,10]").caretPosition = 5
objSess.findById("wnd[0]").sendVKey 2
objSess.findById("wnd[0]/usr/lbl[91,10]").SetFocus
objSess.findById("wnd[0]/usr/lbl[91,10]").caretPosition = 4
objSess.findById("wnd[0]").sendVKey 2
' Display sort dialog (41 = Ctrl+Shift+F5 = menu Edit > Sort in ascending order)
objSess.findById("wnd[0]/tbar[1]/btn[41]").press
' <<<< Here, how to select lines in left and right table controls?
' Downloading the file
fileobjSess.findById("wnd[0]/mbar/menu[5]/menu[5]/menu[2]/menu[1]").Select
objSess.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select
objSess.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").SetFocus
objSess.findById("wnd[1]/tbar[0]/btn[0]").press
objSess.findById("wnd[1]/usr/ctxtDY_PATH").Text = ffilepath
objSess.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = ffilename
objSess.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 8
objSess.findById("wnd[1]/tbar[0]/btn[11]").press
Exit Sub
disperr:
MsgBox "Error occured while retrieving data", vbCritical + vbOKOnly
End Sub
To select a row by its position in a table control, you need to determine the name of the table control, then use the method tableControl.getAbsoluteRow(row) to get the instance of the row, and set its property Selected = True. Example :
tableControl = objSess.findById("wnd[1]/usr/tblSAPLSKBHTC_FIELD_LIST_820")
tableControl.getAbsoluteRow(6).Selected = True
Now, to answer your specific question (ALV sorting in SM37), you also need to press additional buttons to select the Sort fields.
The Sort dialog screen is made of two table controls. You may first press the button "Hide all fields" to move all fields to the right table control (fields not selected), then select the fields on the right table control (as explained in the first paragraph) and press the buttons "Show sel. fields (Ctrl+F3)" and "Copy (Enter)".
You need to know the row number of the field you want to select in the right table control. In an ABAP 7.52 system, these fields are listed in this sequence (first one is row 1, second one is row 2 and so on):
Job name
Spool list
Job documentation
created by
status
start date
start time
duration
...
You also need to know the name of the right table control. For that, you may select the menu System > Status, double click the number of "screen/dynpro" which displays the technical names of screen elements. In your case, you see TC_FIELD_LIST_820. You also see that the screen belongs to the program SAPLSKBH.
The final program would look like this:
ffilepath = "your path here"
ffilename = "Test.txt"
With objSess
.findById("wnd[0]").Maximize
.findById("wnd[0]/tbar[0]/okcd").Text = "/nsm37"
.findById("wnd[0]").sendVKey 0
.findById("wnd[0]/usr/txtBTCH2170-JOBNAME").Text = "*"
.findById("wnd[0]/usr/txtBTCH2170-USERNAME").Text = "*"
.findById("wnd[0]/usr/chkBTCH2170-SCHEDUL").Selected = False
.findById("wnd[0]/usr/chkBTCH2170-READY").Selected = False
.findById("wnd[0]/usr/chkBTCH2170-RUNNING").Selected = False
.findById("wnd[0]/usr/chkBTCH2170-FINISHED").Selected = False
.findById("wnd[0]/usr/chkBTCH2170-ABORTED").Selected = True
.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").Text = Format(Now() - 1, "mm/dd/yyyy")
' .findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").Text = Format(Now() - 1, "dd/mm/yyyy")
.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").Text = Format(Now(), "mm/dd/yyyy")
' .findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").Text = Format(Now(), "dd/mm/yyyy")
.findById("wnd[0]/tbar[1]/btn[8]").press
' Display sort dialog (41 = Ctrl+Shift+F5 = menu Edit > Sort in ascending order)
.findById("wnd[0]/tbar[1]/btn[41]").press
' Remove all previous sort fields (press pushbutton named "APP_FL_ALL")
.findById("wnd[1]/usr/btnAPP_FL_ALL").press
' Select sort field(s) (row 6=start date, row 7=start time)
with .findById("wnd[1]/usr/tblSAPLSKBHTC_FIELD_LIST_820")
.getAbsoluteRow(6).Selected = True
.getAbsoluteRow(7).Selected = True
end with
' Press pushbutton "Show sel. fields"
.findById("wnd[1]/usr/btnAPP_WL_SING").press
' Press key "Enter" (corresponds to pushbutton "Copy (Enter)")
.findById("wnd[1]/tbar[0]/btn[0]").press
' Downloading the file
.findById("wnd[0]/mbar/menu[5]/menu[5]/menu[2]/menu[1]").Select
.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select
.findById("wnd[1]/tbar[0]/btn[0]").press
.findById("wnd[1]/usr/ctxtDY_PATH").Text = ffilepath
.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = ffilename
.findById("wnd[1]/tbar[0]/btn[11]").press
End With

Using excel vba to change the value of a dropdown menu on a website

I am writing an Excel macro to fill out a form on a website. I have written the code that populate the text boxes easily enough, and found code to chose radio boxes, but I am having problems with choosing info from dropdown menus.
Example 'Gender':
The combo box has three options:
Select / Male / Female
I've tried a few variations on this:
doc.getElementsByName("xs_r_gender").Item(0).Value="Male"
...but with no luck.
This is the web source code:
<td> <select name="xs_r_gender" id="xs_r_gender">
<option value="" selected>Select</option>
<option value="male">Male</option>
<option value="female">Female</option> </select></td>
Thanks.
doc.getElementById("xs_r_gender").selectedindex=1
seems to do the trick. (Where 1 represents male)
Though it means I will need to do alot of lookups to determine what the value is for the items in my dropdown. (Easy enough for Sex, where there are only two options, but I have some comboboxes with up to 50 options). If anyone knows of a faster solution, that'd be great. In the meantime, Ill start doing up some tables!!!
thanks.
Try below code assuming doc = ie.document
doc.getElementById("xs_r_gender").value = "Male"
Use this in your code to call the function below.
xOffset = SetSelect(IE.Document.all.Item("shipToStateValue"), "Texas")
doc.getElementById("shipToStateValue").selectedindex = xOffset
Then use this for your function
Function SetSelect(xComboName, xComboValue) As Integer
'Finds an option in a combobox and selects it.
Dim x As Integer
For x = 0 To xComboName.options.Length - 1
If xComboName.options(x).Text = xComboValue Then
xComboName.selectedindex = x
Exit For
End If
Next x
SetSelect = x
End Function
Thanks Stack, works for me! My solution to operate an IE HTML combobox drop down turned out to be two parts.
Part 1 was to click the pull down, here's code:
Dim eUOM1 As MSHTML.HTMLHtmlElement
Set eUOM1 = ie.document.getElementsByTagName("input")(27).NextSibling
eUOM1.Focus
eUOM1.Click
Part 2 was to choose and click the value, like this (*actual element name changed):
Dim eUOM2 As MSHTML.HTMLHtmlElement
Set eUOM2 = ie.document.getElementsByName("[*PutNameHere]")(0)
eUOM2.Value = "EA"
eUOM2.Click
Here are references:refs
You can try the querySelector method of document to apply a CSS selector of option tag with attribute value = 'male':
doc.querySelector("option[value='male']").Click
or
doc.querySelector("option[value='male']").Selected = True
Function SetSelect(s, val) As Boolean
'Selects an item (val) from a combobox (s)
'Usage:
'If Not SetSelect(IE.Document.all.Item("tspan"), "Custom") Then
'something went wrong
'Else
'continue...
'End If
Dim x As Integer
Dim r As Boolean
r = False
For x = 0 To s.Options.Length - 1
If s.Options(x).Text = val Then
s.selectedIndex = x
r = True
Exit For
End If
Next x
SetSelect = r
End Function
Try this code :
doc.getElementById("xs_r_gender").value = "Male"
doc.getElementById("xs_r_gender").FireEvent("onchange")
You can do something like this:
doc.getElementsByName("xs_r_gender").Item(1).Selected=True
or
doc.getElementById("xs_r_gender").selectedindex = 1
Where 1 is the male option (in both cases).
If the dropbox needs to fire some event in order to aknowledge your choice, it is likely that it will be the "onchange" event. You can fire it like so:
doc.getElementById("xs_r_gender").FireEvent("onchange")
If you ever want to be able to select an option based on the option's text you can use the function given by Lansman (here) .
Based on the same answer, if you want to call the option by it's value property (instead of the text, you can just change the line If xComboName.Options(x).Text = xComboValue Then to If xComboName.Options(x).value = xComboValue Then).
This should cover all bases.
Copy from Here till last line:
Sub Filldata()
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For X = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(X).document.Location
my_title = objShell.Windows(X).document.Title
If my_title Like "***Write your page name***" Then
Set IE = objShell.Windows(X)
Exit For
Else
End If
Next
With IE.document.forms("***write your form name***")
' Assuming you r picking values from MS Excel Sheet1 cell A2
i=sheet1.range("A2").value
.all("xs_r_gender").Item(i).Selected = True
End with
End sub

Resources