UserForm adding data from textbox and optionbutton to worksheet

Tdorman

Board Regular
Joined
Aug 12, 2021
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am trying to add data to a worksheet through a UserForm. I have 6 rows of data in the UserForm with 3 columns of text boxes and 1 column with option buttons. I am running into an issue where the option buttons are being inserted after the text boxes, so i have the text box data all on the correct rows, then that data is repeated with the data from the option buttons. So if I enter three rows of new information I will end up with the three rows for the text boxes and then another three rows for the option buttons.

I am also running into an issue where I can only check off one option button. There will be times where all of some of the buttons will be checked off. How do I make it so multiple can be checked?

VBA Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet


Set ws = ThisWorkbook.Sheets("DATA Member-19")


LastRow = ws.Cells(Rows.Count, 4).End(xlUp).Row

ws.Cells(LastRow + 1, 2).Value = TextBox1.Value
ws.Cells(LastRow + 2, 2).Value = TextBox2.Value
ws.Cells(LastRow + 3, 2).Value = TextBox3.Value
ws.Cells(LastRow + 4, 2).Value = TextBox4.Value
ws.Cells(LastRow + 5, 2).Value = TextBox5.Value
ws.Cells(LastRow + 6, 2).Value = TextBox6.Value

ws.Cells(LastRow + 1, 3).Value = TextBox7.Value
ws.Cells(LastRow + 2, 3).Value = TextBox8.Value
ws.Cells(LastRow + 3, 3).Value = TextBox9.Value
ws.Cells(LastRow + 4, 3).Value = TextBox10.Value
ws.Cells(LastRow + 5, 3).Value = TextBox11.Value
ws.Cells(LastRow + 6, 3).Value = TextBox12.Value

ws.Cells(LastRow + 1, 4).Value = TextBox13.Value
ws.Cells(LastRow + 2, 4).Value = TextBox14.Value
ws.Cells(LastRow + 3, 4).Value = TextBox15.Value
ws.Cells(LastRow + 4, 4).Value = TextBox16.Value
ws.Cells(LastRow + 5, 4).Value = TextBox17.Value
ws.Cells(LastRow + 6, 4).Value = TextBox18.Value

If OptionButton1.Value = True Then ws.Cells(LastRow + 1, 15).Value = "X": OptionButton1.Value = ""
If OptionButton2.Value = True Then ws.Cells(LastRow + 2, 15).Value = "X": OptionButton2.Value = ""
If OptionButton3.Value = True Then ws.Cells(LastRow + 3, 15).Value = "X": OptionButton3.Value = ""
If OptionButton4.Value = True Then ws.Cells(LastRow + 4, 15).Value = "X": OptionButton4.Value = ""
If OptionButton5.Value = True Then ws.Cells(LastRow + 5, 15).Value = "X": OptionButton5.Value = ""
If OptionButton6.Value = True Then ws.Cells(LastRow + 6, 15).Value = "X": OptionButton6.Value = ""


MsgBox ("Members added successfully")

End Sub

I need each row to transfer over on the same line, which is happening for the text boxes, just not the option button. Also need to be able to check off multiple buttons, not just one. Thank you for your help
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
If you want to select multiple option buttons, then change them to checkboxes instead.
At the moment if you select option button 1 an X will appear in the same row as textbox 1,7 & 13. Is that not what you want?
 
Upvote 0
Solution
Thanks for the help! Yes, Option button, or check box now, would be in that same row as those textboxes. Thanks again
 
Upvote 0
But that is what your code does. Option 1 will be on the same row as textbox1, option2 on the same row as textbox2 etc.
 
Upvote 0
For whatever reason its placing the X on different lines. For example, I just ran the UserForm and had a check for the second and fifth row and it placed the X on the third and sixth row that was added out of the six.
 
Upvote 0
The only check box that seems to remain correct is the first Check Box. Each box after that doesn't appear on the correct row
 
Upvote 0
Do you have any merged cells, as it doesn't do that for me.
 
Upvote 0
Could it be because its adding it to a table? Would that impact only one of the data sets and not the rest?
 
Upvote 0
Wow, I feel dumb. The check boxes were out of order on the UserForm itself. Its working fine now, thanks for the help
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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