How to pass form selection values into vba module

ChanchalSingh

New Member
Joined
May 29, 2022
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
I have created a form which shows multiple checkbox with submit button. I need below 2 things to be done.
1. On click of submit button, how to capture selected checkbox numbers and stored into a variable? Assume there are 5 checkbox and I selected 2 checkboxes(2nd and 4th) then variable should store 2,4
2. How to pass that variable to module. (Basically I want the form should be called inside the module and return checkbox selection values as variable which is used for next steps.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I have created a form which shows multiple checkbox with submit button. I need below 2 things to be done.
1. On click of submit button, how to capture selected checkbox numbers and stored into a variable? Assume there are 5 checkbox and I selected 2 checkboxes(2nd and 4th) then variable should store 2,4
2. How to pass that variable to module. (Basically I want the form should be called inside the module and return checkbox selection values as variable which is used for next steps.

I am using below code in form to create checkbox: (no of headers columns in sheet1 = no of check boxes displayed in output)

Option Explicit

Private Sub UserForm_Initialize()

Dim LastColumn As Long
Dim i As Long
Dim chkBox As MSForms.CheckBox

LastColumn = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column

For i = 1 To LastColumn
Set chkBox = Me.Controls.Add("Forms.CheckBox.1", "CheckBox_" & i)
chkBox.Caption = Worksheets("Sheet1").Cells(1, i).Value
chkBox.Left = 5
chkBox.Top = 5 + ((i - 1) * 20)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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