Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50162

Populating a text area in a user form from an Array???

$
0
0
Hello everyone,

I am building a userform for when I am giving an oral quiz with students. I typically have 5 topics to cover for each quiz. There are 8 quizzes total.

I started playing around with combo boxes for scores, and have a list with a 0-10 scale that I use for each question that works great. Playing off of that success, I built an 8 wide by 5 high array with all of my topics that I cover for all of the quizzes. I then have a combo box for question 1, another for question 2, etc. I just have to click it, and then pull up the topic from the list. It works great, but I got to thinking that it would be nice if I could just say which quiz it was, and it would put the correct question into a text box for me, so that I could spend my time listening instead of clicking, and maybe even be able to edit the topic.

I go on to process the values into a comment that looks like:

We discussed Radioactive Decay (10/10),Half life (0/10),Fission and Fusion (10/10),Renewable Energy (5/10), and Biotechnology (5/10)

My array looks something like:
Quiz1 Quiz2 Quiz3 Quiz4 Quiz5 Quiz6 Quiz7 Quiz8
Q1 Q1 Q1 Q1 Q1 Q1 Q1 Q1
Q2 Q2 Q2 Q2 Q2 Q2 Q2 Q2
Q3 Q3 Q3 Q3 Q3 Q3 Q3 Q3
Q4 Q4 Q4 Q4 Q4 Q4 Q4 Q4
Q5 Q5 Q5 Q5 Q5 Q5 Q5 Q5

And I want to pull up the correct Q1, Q2, Q3, Q4, and Q5 depending on the Quiz selected from a combo box. I would like the value for each Q to be in its own (if possible editable) text box.

Does anyone have any ideas for how to pull that off?

Here is the code I am currently using:

Private Sub RecordScores_Click()

Dim Total As Single


Set ws = Worksheets("DBAs")
rRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ws.Cells(rRow, 1).Value = Me.StudentName.Value
ws.Cells(rRow, 2).Value = Me.DBA.Value
ws.Cells(rRow, 3).Value = Me.Question1.Value
ws.Cells(rRow, 4).Value = Me.Score1.Value
ws.Cells(rRow, 5).Value = Me.Question2.Value
ws.Cells(rRow, 6).Value = Me.Score2.Value
ws.Cells(rRow, 7).Value = Me.Question3.Value
ws.Cells(rRow, 8).Value = Me.Score3.Value
ws.Cells(rRow, 9).Value = Me.Question4.Value
ws.Cells(rRow, 10).Value = Me.Score4.Value
ws.Cells(rRow, 11).Value = Me.Question5.Value
ws.Cells(rRow, 12).Value = Me.Score5.Value
ws.Cells(rRow, 13).Value = Now
ws.Cells(rRow, 14).Value = "Completed"



Me.StudentName.Value = ""
Me.DBA.Value = ""
Me.Question1.Value = ""
Me.Score1.Value = ""
Me.Question2.Value = ""
Me.Score2.Value = ""
Me.Question3.Value = ""
Me.Score3.Value = ""
Me.Question4.Value = ""
Me.Score4.Value = ""
Me.Question5.Value = ""
Me.Score5.Value = ""


End Sub

Private Sub Aborted_Click()


Set ws = Worksheets("DBAs")
rRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ws.Cells(rRow, 1).Value = Me.StudentName.Value
ws.Cells(rRow, 2).Value = Me.DBA.Value
ws.Cells(rRow, 3).Value = Me.Question1.Value
ws.Cells(rRow, 4).Value = Me.Score1.Value
ws.Cells(rRow, 5).Value = Me.Question2.Value
ws.Cells(rRow, 6).Value = Me.Score2.Value
ws.Cells(rRow, 7).Value = Me.Question3.Value
ws.Cells(rRow, 8).Value = Me.Score3.Value
ws.Cells(rRow, 9).Value = Me.Question4.Value
ws.Cells(rRow, 10).Value = Me.Score4.Value
ws.Cells(rRow, 11).Value = Me.Question5.Value
ws.Cells(rRow, 12).Value = Me.Score5.Value
ws.Cells(rRow, 13).Value = Now
ws.Cells(rRow, 14).Value = "Aborted"

Me.StudentName.Value = ""
Me.DBA.Value = ""
Me.Question1.Value = ""
Me.Score1.Value = ""
Me.Question2.Value = ""
Me.Score2.Value ""
Me.Question3.Value = ""
Me.Score3.Value = ""
Me.Question4.Value = ""
Me.Score4.Value = ""
Me.Question5.Value = ""
Me.Score5.Value = ""

Viewing all articles
Browse latest Browse all 50162

Trending Articles