Schadenfreud
New Member
- Joined
- Jan 22, 2014
- Messages
- 29
Hello, I've just started using the VBA and am trying to create an Excel UserForm, which lists all visible Sheets in the current file (doesn't list hidden ones) andcreates a checkbox in front of each Sheet name, which will hide/show the Sheet, depending on it being true/false. The Form must be scrollable and there must be a validation, checking that there's no less than one visible Sheet at any given time.
So far I'm stuck at the populating the form with checkboxes part. I need them to appear one below the other with the sheet name beside them.
My code so far looks like this (and doesn't work apparently):
P.s. I'm sure I have to somehow add coordinates for where the checkboxes should appear too, but I don't know how to do that either.
So far I'm stuck at the populating the form with checkboxes part. I need them to appear one below the other with the sheet name beside them.
My code so far looks like this (and doesn't work apparently):
Code:
Private Sub UserForm_Initialize()
Private WithEvents Chk As MSForms.CheckBox
Dim myWorksheet As Worksheet
For Each myWorksheet In Worksheets
If myWorksheet.Visible = xlSheetVisible Then
'add the checkboxes for each visible worksheet to the form
Set Chk = frmShowTabs.Controls.Add("Forms.CheckBox.1", "myWorksheet.Name")
End If
Next
End Sub
P.s. I'm sure I have to somehow add coordinates for where the checkboxes should appear too, but I don't know how to do that either.