VBA for saving to a resultant row number

Chicken6

New Member
Joined
Dec 30, 2012
Messages
15
Hi all,
In a psych experiment I am using forms where my participants enter their Participant Number in a textbox (TextBoxSubjectNumber, which saves to cell A2) then complete some psychological questions which have 5 choices (Strongly disagree, disagree, neutral, agree and strongly agree). Each choice has an OptionBox and each is given a score 1-5. The score saves in one row (one participant per row). This code below works well.

However the participants do the experiment over two days, and there are more questions to answer. I want the answer scores to be saved in the same row.

How can I have subsequent data saved in a row which coincides with the participant number? So instead of saving to Range("B2"), it saves to something like ("B,TextBoxSubjectNumber.text")


Current code:

'enter your participant number
Private Sub TextBoxSubjectNumber_AfterUpdate()
Sheets("IndDiff").Range("A2").Value = TextBoxSubjectNumber.Text
End Sub

Private Sub OptionBox11_Click()
Sheets("IndDiff").Range("B2").Value = "1"
End Sub
Private Sub OptionBox12_Click()
Sheets("IndDiff").Range("B2").Value = "2"
End Sub
Private Sub OptionBox13_Click()
Sheets("IndDiff").Range("B2").Value = "3"
End Sub
Private Sub OptionBox14_Click()
Sheets("IndDiff").Range("B2").Value = "4"
End Sub
Private Sub OptionBox15_Click()
Sheets("IndDiff").Range("B2").Value = "5"
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hello

Welcome to MrExcel. Here's example code:

Code:
'enter your participant numberPrivate Sub TextBoxSubjectNumber_AfterUpdate()
    Sheets("IndDiff").Range("A2").Value = TextBoxSubjectNumber.Text
End Sub


Private Sub OptionBox11_Click()
    WriteDown 1
End Sub
Private Sub OptionBox12_Click()
    WriteDown 2
End Sub
Private Sub OptionBox13_Click()
    WriteDown 3
End Sub
Private Sub OptionBox14_Click()
    WriteDown 4
End Sub
Private Sub OptionBox15_Click()
    WriteDown 5
End Sub


Sub WriteDown(si As Single)


    Dim rngFoundCell As Range


    With Sheets("IndDiff")
        Set rngFoundCell = .Columns(1).Find(.Range("A2").Value, , xlValues, xlWhole)
        If Not rngFoundCell Is Nothing Then
            .Range("B" & rngFoundCell.Row).Value = si
        End If
    End With


    Set rngFoundCell = Nothing


End Sub

Can you please use
Code:
 tags here? Thanks.
 
Upvote 0
Hi Wigi,
thank you so much for your reply. I will try it. I will work out how to use the
Code:
 tags as well.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,216,773
Messages
6,132,641
Members
449,739
Latest member
tinkdrummer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top