Ciao Ringo,
sono giorni che mi arrovello per creare una userform che, una volta inizializzata, mi vengano creati automaticamente delle Label e delle combobox in base alle colonne piene di un foglio attivo (Numero colonne variabili).
vale a dire:
Foglio1
3 colonne
Userform
3 Label
3 combobox
Foglio 2
6 colonne
6 Label
6 Combobox
Spero sia fattibile
Sarebbe stato utile vedere il codice dei tuoi tentativi!
Comunque, prova qualcosa del genere:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim iCols As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
iCols = SH.UsedRange.Columns.Count
Call CreaUserform(iCols, "Demo")
End Sub
'--------->>
Public Function CreaUserform(iCols As Long, sTitle As String)
Dim myUserform As Object
Dim myComboBox As Msforms.ComboBox
Dim myLabel As Msforms.Label
Dim myCommandButton1 As Msforms.CommandButton
Dim i As Long, j As Long
Dim TopPos As Double
Dim dLeft As Double, dGap As Double
Set myUserform = ThisWorkbook.VBProject.VBComponents.Add(3)
myUserform.Properties("Width") = 800
TopPos = 5
dGap = 12
For i = 1 To iCols
Set myLabel = myUserform.Designer.Controls _
.Add("Forms.Label.1")
Set myComboBox = myUserform.Designer.Controls _
.Add("Forms.ComboBox.1")
With myLabel
.Width = 100
.Height = 18
.Left = 8
.Caption = "Pippo_" & i
.Top = TopPos
End With
With myComboBox
.Width = 100
.Height = 18
.Left = 8
.Top = TopPos + dGap
.Tag = i
dLeft = .Left + .Width + 5
End With
TopPos = TopPos + 30 + dGap
Next i
Set myCommandButton1 = myUserform.Designer.Controls. _
Add("forms.CommandButton.1")
With myCommandButton1
.Caption = "Esci"
.Height = 18
.Width = 60
.Left = dLeft
.Top = TopPos - 30 + dGap
End With
With myUserform.CodeModule
j = .CountOfLines
.InsertLines j + 1, "Sub CommandButton1_Click()"
.InsertLines j + 2, " Unload Me"
.InsertLines j + 3, "End Sub"
End With
With myUserform.Properties
.Item("Caption") = sTitle
.Item("Width") = myCommandButton1.Left _
+ myCommandButton1.Width + 15
.Item("Height") = TopPos + 24
End With
VBA.UserForms.Add(myUserform.Name).Show
ThisWorkbook.VBProject.VBComponents. _
Remove VBComponent:=myUserform
End Function
'<<=========
Eseguendo la macro Tester, e con tre colonne di dati sul f0oglio di interesse. vedo la seguente Userform:

Con 6 colonne di dati, ottengo invece:

Infatti, in accordo con la tua richiesta, la Userform si espanderà per adattarsi al numero di ciascun tipo di controllo, che varierà per eguagliare il numero di colonne contigue di dati.
Pertanto, aumentando il numero di colonne con dati a 10, otterò una Userform con 10 ComboBox e 10 Label e l'altezza della userform si adatterà per accomodare tutti i controlli:

Nota, inoltre, che con questo ho aggiunto un controllo CommandButton ed ho dinamicamente assegnato codice al CommandButton per chiudere la Userform .
Potresti scaricare il mio file di prova Ringo20180518.xlsm
===
Regards,
Norman
