PDA

View Full Version : Solved: Trouble with syntax?



paulked
04-24-2013, 08:20 AM
Hi

I am trying to fill CheckBox captions in a userform from a column in a Sheet1 (where the userform is called from). I have added a userform and put 14 checkbox's in all with the caption "Not used".

Private Sub UserForm_Initialize()
Dim cl as Range
Dim LastRow as Long
Dim i
Set cl = Cells(i, 1)
cl.Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
Me("CheckBox" & i).Caption = cl.Value
Next
End Sub

I've tried all sorts of syntax for the line Me("CheckBox" & i).Cation = cl.Value but can't get any to work.

Any Help please?

JKwan
04-24-2013, 09:23 AM
try this

Private Sub UserForm_Initialize()
Dim cl As Range
Dim LastRow As Long
Dim i
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
Set cl = Cells(i, 1)
cl.Select

Me.Controls("CheckBox" & i).Caption = cl.Value
Next
End Sub

paulked
04-24-2013, 09:35 AM
Fantastic :)

Many thanks

snb
04-24-2013, 09:54 AM
It's not unimportant to refer to the sheet, that contains the values; otherwise you could get unpredictable results.



Private Sub UserForm_Initialize()
For j = 1 To sheets("Sheet1").columns(1).specialcells(2).count
Me("CheckBox" & j).Caption =sheets("Sheet1").cells(j,1).Value
Next
End Sub

paulked
04-24-2013, 09:59 AM
Sublime :clap2: