View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default PLEASE HELP: Index and Match function in Userform to populate

Hey Dave, to make it clear. Here is and eg of how the data looks on sheet

Tasks Roll_No
3 11
5 11
4 12
6 12
2 13
5 13
3 14
4 14
1 15
2 15
1 16
4 16

So lets say you select "12" from Roll_No column filter
then it will display

Tasks Roll_No(filter)
4 12
6 12

So I want this 4 and 6 to be displayed in the dropdown list on userform too
Is there a way to capture filter values(4 and 6) from a sheet to a userfrom.
So when I input "12" on userform textbox I se 4 and 6 for my Tasks Dropdown
on the userform.

Hope I made it clear

"Dave Peterson" wrote:

Once you find the cell that holds the name, you can use VBA's split command (if
you're using xl2k or higher) to parse that data into an array.

Then use that array as the combobox's .list.

Dim myStr As String
Dim myArr As Variant

myStr = "1,2,3" 'how ever you find that cell would go here

myArr = Split(myStr, ",")

With Me.ComboBox1
.Clear
.List = myArr
End With

sam wrote:

Thanks a lot for you help Dave,
One more thing I wanted in my form was a way to capture filter values from
sheet2 into a Dropdown list in the user form. Is there a way to do this?

For eg, I have a column "Tasks" on sheet2 which have values 1,2,3,4,5,6 and
each student can have multiple "Tasks" such as..

John: 1,3
Jill: 1,5
jack: 3,5,6
Bill: 2,4,6
and so on... I have this column set as a filter(Behaves like a dropdown on
excel sheet), so John will have a Dropdown Filter with values 1 and 3 in
"Tasks" column

So basically, I want these filter values to be displayed on the form as
dropdown menu with 1 and 3 displayed for John.

Hope I made it clear

Thanks in advance

"Dave Peterson" wrote:

Dim res as variant

with worksheets("sheet2") 'I'd change the name to something meaningful
'look for a match using a string
res = application.match(me.textbox1.value,.range("A:A"), 0)
if iserror(res) then
'look for a match using a real number
res = application.match(clng(me.textbox1.value),.range(" A:a"),0)
end if

if iserror(res) then
'no match between textbox1 and column A of Sheet2
'what should happen
beep
msgbox "Invalid entry"
exit sub '???
end if

me.textbox2.value = .range("a:a")(res).offset(0,1).value 'column b
me.textbox3.value = .range("a:a")(res).offset(0,5).value 'column F
End with

(Untested, uncompiled. Watch for typos.)


sam wrote:

Hi All,

How can I use Inded and Match function on VBA to populate certain form fields?

For eg: I have a userform where Users input:

Roll No(Unique to every student):
Last Name :
First Name :
Subject1 :
Ph No:

What I want to do is: Once Users Input Their Roll No, I want to populate
their Last Name, First Name, Subject1 and Ph No. Also the roll number might
not be in descending order, Hence I want to use somethign like Index and
Match function, So once a student Inputs the roll number, It will match the
roll number and populate other fields respectively

The button to launch the Form is on Sheet1 and All the student data is in
Sheet2.

Hope I made it clear

Thanks in Advance

--

Dave Peterson


--

Dave Peterson