totalchaos
New Member
- Joined
- Jul 6, 2012
- Messages
- 40
I have this code in the initialize event of a userform in excel vba:
Private Sub UserForm_Initialize()
Dim ws As Worksheet, iCol As Integer, iRow As Integer, _
a As Integer, b As Integer
Set ws = ActiveWorkbook.Worksheets("Sheet1")
iCol = 1
iRow = 20
a = iRow
For a = 2 To iRow
cbPeriodEnd.AddItem CStr(ws.Cells(a, iCol))
Next a
cbPeriodEnd.Text = cbPeriodEnd.List(0, 0) 'first item
End Sub
In range A1:A20 of Sheet1 I have:
PeriodEnd
2/26/2012
3/4/2012
3/11/2012
3/18/2012
3/25/2012
4/1/2012
4/8/2012
4/15/2012
4/22/2012
4/29/2012
5/6/2012
5/13/2012
5/20/2012
5/27/2012
6/3/2012
6/10/2012
6/17/2012
6/24/2012
7/1/2012
When I run the code, the dropdown box cuts off the last two digits of each date. The textalign property for the
combobox is frmtextalignright. All other properties are default. Can anyone help me fix this? I'm sure it's something
simple I'm overlooking.
Private Sub UserForm_Initialize()
Dim ws As Worksheet, iCol As Integer, iRow As Integer, _
a As Integer, b As Integer
Set ws = ActiveWorkbook.Worksheets("Sheet1")
iCol = 1
iRow = 20
a = iRow
For a = 2 To iRow
cbPeriodEnd.AddItem CStr(ws.Cells(a, iCol))
Next a
cbPeriodEnd.Text = cbPeriodEnd.List(0, 0) 'first item
End Sub
In range A1:A20 of Sheet1 I have:
PeriodEnd
2/26/2012
3/4/2012
3/11/2012
3/18/2012
3/25/2012
4/1/2012
4/8/2012
4/15/2012
4/22/2012
4/29/2012
5/6/2012
5/13/2012
5/20/2012
5/27/2012
6/3/2012
6/10/2012
6/17/2012
6/24/2012
7/1/2012
When I run the code, the dropdown box cuts off the last two digits of each date. The textalign property for the
combobox is frmtextalignright. All other properties are default. Can anyone help me fix this? I'm sure it's something
simple I'm overlooking.