0

I have an excel document that has 5 successive cells on 1 column that need to be filled in with data. I am looking to create a VBA userForm that will go through a line of questioning to help the user input the correct data.

Lets say that the 5 cells are A1 through A5. Once the userform is called it should show a question(label maybe?), A text box for the input of data, and a command button to move on the the next question. all the while moving from A1 to A2 and so on until the line of questioning is done.

Does anybody have any idea how to accomplish this? My VB knowledge is basic but i have tried and tried to no avail.

Thanks in advance!

1
  • What have you tried so far? Do you have any code as of now? You may need to have a look at The StackOverflow How To Ask Page you have a couple options Either on button click set Range("A" & QuestionNumber).Value to TextBox.Value. OR fill in a couple variables A1,A2,A3,A4,A5 each time the questions are answered then write them all to the range at the end. Commented Jun 28, 2013 at 14:42

1 Answer 1

2

Given a form like this:

UserForm

You could set your questions up in an array and iterate through them each button press while setting the answers to your sheet.

Dim i As Integer
Dim str(1 To 3) As String

Private Sub UserForm_Initialize()
    i = 1
    str(1) = "Question 1"
    str(2) = "Question 2"
    str(3) = "Question 3"

    btnNext.Default = True
    lblQuestion.Caption = str(i)
    txtAnswer.SetFocus
End Sub

Private Sub btnNext_Click()
    Sheets("Sheet1").Cells(i, 1).Value = txtAnswer.Text
    i = i + 1
    If i = UBound(str) + 1 Then
        UserForm1.Hide
        Exit Sub
    End If
    lblQuestion.Caption = str(i)
    txtAnswer.Text = ""
    txtAnswer.SetFocus
End Sub

Example of Result: Result

Sign up to request clarification or add additional context in comments.

1 Comment

If i could +1 you i would. That is exactly what i was looking to do. Thank you a million.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.