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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,215,341
Messages
6,124,391
Members
449,155
Latest member
ravioli44

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