I want an user to select on which sheets he wants to create a new line of text. But the number of sheets he is able to select may vary over time and I don't want to hardcode the sheets' name.
Here is an example ("o" represents the checkbox) of what I aim to do:
o 01.2013
o 07.2013
o 01.2014
o 07.2014
I created an userform with an empty frame to put my checkboxes, and added this bit of code to the userform:
Private Tck(10) As MSForms.CheckBox
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim i As Long
i = 1
For Each ws In ActiveWorkbook.Worksheets
If Left(ws.Name, 3) = "T2M" Then
Set Tck(i) = Frame1.Controls.Add("Forms.Checkbox.1", "Checkbox" & i)
Tck(i).Caption = Right(ws.Name, 7)
i=i+1
End If
Next
End Sub
But it only adds one checkbox with the last sheet which validates the if test.
I tried to make an offset between the two iterations but I can't modify the position of the Tck(i) using Tck(i).top for example.
I also tried the method from the answer of this question : Adding controls to a frame in an Excel userform with VBA but it dosen't work either.