3
votes

I have a user form with three comboboxes and one text box that I would like to populate with named ranges or public variables. I am working in Excel 2010 on Windows. Here is what I have: First I run through some code that converts one worksheet into a new configuration. I then call the userform which will set up the variables necessary to update the worksheet further. I have done this on a Mac and it works, but I am transitioning this from the mac to a windows server. I thought this would be the easy part but it in not working for some reason.

Here is the code for the userform.

Public KorS As String
Public ActivityID As String
Public Stage As String
Public varsaveme As String


Private Sub ufStageDt_Initialize()

AD = varsaveme & ".xls"
duh = KorS

Set Me.tbAdName.Text = duh
Set UserForm1.Caption = AD

'Set Me.cmbLowDt.List = "AnnDt"
Set Me.cmbHighDt.List = "AnnDt"
Set Me.cmbStage.List = "Stage"
Me.cmbLowDt.List = "AnnDt"

End Sub

The public variables are present in the code on the worksheet.

Here is the code that I used on the Mac.

Private Sub UserForm_Initialize()

Ad = varsaveme & ".xls"

duh = KorS

tbAdName.Text = varsaveme
UserForm.Caption = Ad


cmbLowDt.List = Range("AnnDt").Value
cmbHighDt.List = Range("AnnDt").Value
cmbStage.List = Range("Stage").Text

End Sub

Any assistance would be greatly appreciated. I am using the ufStageDt.Show command in the vba script to bring up the userform.

1

1 Answers

5
votes

Set won't work, so eliminate that. Also, List expects an array. For a single hard-coded item, use Additem.

Me.cmbHighDt.Additem "AnnDt"

EDIT: "AnnDt" is a named range:

Me.cmbHighDt.List = Application.Transpose(ActiveSheet.Range("AnnDt"))

EDIT2: For dates:

Private Sub UserForm_Initialize()
Dim i As Long
With Me.cmbHighDt
    .List = Application.Transpose(ActiveSheet.Range("AnnDt"))
    For i = 0 To .ListCount - 1
        .List(i) = Format(.List(i), "yyyy-mm-dd")
    Next i

    'to get it back to a date
    ActiveSheet.Range("B1") = DateValue(.List(0))
End With

End Sub