PDA

View Full Version : Solved: Return a value from another sheet



Helpmepls
02-23-2013, 10:33 PM
Hi, I have what is probably a basic query, but simply don’t know enoughVBA code to pull this together.
I have an excel sheet with 2 sheets. Sheet1 is called QuestionSetA and Sheet2 is called QuestionSetB. Both sheets have the same structure:
Column A lists thequestion numbers
Column B lists thequestion
Column C lists theanswer
I have also set up a user form. The user form has 2 comboboxes. Combobox 1 has a dropdown list where the user can select QuestionSetA orQuestionSetB.
Combobox2 the allows the user to select the question they want ananswer for.
On the user form I also have a button and 2 text boxes.
What I would like is to be ableto select the desired questionset from combobox1 and the desired questionnumber from combobox 2, click the button and have some code go to which eversheet was selected, identify if the question number and display the questiontext in one text box and the answer in the other textbox. Hoping someone can help me. Many thanks

Kenneth Hobs
02-25-2013, 06:59 AM
Welcome to the forum!

Work up a simple example and attach it so that we can help you more readily.

Helpmepls
02-26-2013, 03:13 AM
Thanks Kenneth. Not sure if this will be adequate but have attached a knockup version.
In the user formthe user can select either questionset1 or questionset2 in combobox 1. In combobox 2 they can then select thequestion number that they are seeking the answer for.
I’d then like the user to be able to click the lookup buttonand populate the text boxes below with the question in the top text box and theanswer in the bottom text box.
Thanks again.

Helpmepls
02-28-2013, 02:01 PM
Hi again... ok so I have been researching, researching, researching and I think I'm getting somewhere - but still needing some help. I've attached a new file (version 6). I am now able to find a question number and display both the question and the answer in the textboxes... but... I have 2 different worksheets (QuestionSet1 & QuestionSet2) and I was going to have a combobox for the user to select one or the other. Then dependent on that selection the user can select a question number and have the question and answer from the selected questionset display and I don't know how to make that happen. I hope that makes sense. Code is below:

Private Sub UserForm_Initialize()
Dim R As Long
ComboBox1.RowSource = ""
For R = 1 To 300
ComboBox1.AddItem Sheets("QuestionSet1").Range("A" & R).Value
Next R
End Sub
Private Sub ComboBox1_Change()
Dim R As Long
R = Me.ComboBox1.ListIndex + 1
Me.TextBox1.Value = Cells(R, 2).Value
Me.TextBox2.Value = Cells(R, 3).Value
End Sub