Userform - 100 checkbox (10X10)

  • Thread starter Thread starter Alex St-Pierre
  • Start date Start date
A

Alex St-Pierre

Hi,
Is there a way to make a listview or something else that will contains 10
rows and 10 columns of checkbox only? So, the listview could contains 100
cases to click.
Thank you!
Alex
 
This adds to a form with a scrollable frame 100 checkboxes.
Create a UserForm, Frame (Frame1), CommandButton (CommandButton1) and stick
the code behind the form:

Private Sub CommandButton1_Click()
Dim x As Integer, y As Integer
Dim chk As MSForms.CheckBox, dblBuffer As Double
Dim TopPos As Double, LeftPos As Double, OrigLeft As Double
Frame1.ScrollBars = fmScrollBarsBoth
' Adjust the initial left and top to adjust
' the initial starting (top left) starting point
OrigLeft = 5: TopPos = 5: LeftPos = OrigLeft
' Adjust the buffer to adjust the spacing between the controls
dblBuffer = 2
For x = 1 To 10
For y = 1 To 10
Set chk = Me.AddCheckbox(TopPos:=TopPos, LeftPos:=LeftPos,
Width:=15)
LeftPos = LeftPos + chk.Width + dblBuffer
Frame1.ScrollWidth = LeftPos + chk.Width
Next
TopPos = chk.Top + chk.Height + dblBuffer
LeftPos = OrigLeft
Frame1.ScrollHeight = chk.Top + chk.Height
Next
End Sub

Function AddCheckbox(ByVal TopPos As Double, ByVal LeftPos As Double, ByVal
Width As Double, _
Optional ByVal Height As Double = 18) As MSForms.CheckBox
Dim Ctrl As MSForms.CheckBox
Set Ctrl = Me.Frame1.Controls.Add("Forms.Checkbox.1", "")
With Ctrl
.Top = TopPos
.Left = LeftPos
.Width = Width
.Height = Height
End With
Set AddCheckbox = Ctrl
End Function
 
It works well !! I'm wondering if there's a way to place each checkbox inside
a listview cases?
Thanks!
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top