PDA

View Full Version : [SOLVED:] Please Help! Code For Multiple Checkbox Returning to One cell in Excel VBA User Form



Michelle RSC
07-05-2022, 06:14 AM
Good afternoon all,

After reading many articles and watching multiple youtube tutorials, I am still stuck on how to code my checkbox options to all report to a single cell (TargetRow, 18) - (S4:S100000) in "Database" (Excel Spreadsheet).

This is what the page of my user form looks like:

29908

For "Bait", I have checkbox options for:
Sardine ("Check_Bait_Squid"),
Squid ("Check_Bait_Sard"),
Prawn ("Check_Bait_Prawn"),
Redbait ("Check_Bait_Redbait"),
Worm ("Check_Bait_Worm"),
Mussel ("Check_Bait_Mussel"),
Mullet ("Check_Bait_Mullet")

If a user selects multiple checkboxes, which is allowed, I would like all responses to report to Column S (S4:S100000), separated by a comma.

I am using my "Next" command button to save the data and move to the next page of the user form, simultaneously.

I do already have these options assigned to a GroupName, "Bait".

Please help with simple code that I can understand and modify as needed. I am a newbie, please keep that in mind.

Aussiebear
07-05-2022, 02:45 PM
Have a look at the Excel function TextJoin

Paul_Hossler
07-05-2022, 03:07 PM
Lot of missing information in the post.

I assume that Check_Bait_Squid (et. al) is the name of the checkbox control which reurns true or false

Might give you some ideas





Sub test()
Dim s As String


If Check_Bait_Squid Then s = "Squid,"
If Check_Bait_Sard Then s = s & "Sard,"
If Check_Bait_Prawn Then s = s & "Prawn,"
If Check_Bait_Redbait Then s = s & "Redbait,"
If Check_Bait_Worm Then s = s & "Worm,"
If Check_Bait_Mussel Then s = s & "Mussel,"
If Check_Bait_Mullet Then s = s & "Mullet,"


If Right(s, 1) = "," Then s = Left(s, Len(s) - 1)

Range("S1234").Value = s




End Sub

Michelle RSC
07-05-2022, 10:16 PM
Lot of missing information in the post.

I assume that Check_Bait_Squid (et. al) is the name of the checkbox control which reurns true or false

Might give you some ideas





Sub test()
Dim s As String


If Check_Bait_Squid Then s = "Squid,"
If Check_Bait_Sard Then s = s & "Sard,"
If Check_Bait_Prawn Then s = s & "Prawn,"
If Check_Bait_Redbait Then s = s & "Redbait,"
If Check_Bait_Worm Then s = s & "Worm,"
If Check_Bait_Mussel Then s = s & "Mussel,"
If Check_Bait_Mullet Then s = s & "Mullet,"


If Right(s, 1) = "," Then s = Left(s, Len(s) - 1)

Range("S1234").Value = s




End Sub