I am still getting variable not set on this line
ReDim Preserve Name(1 To nList)
Option Explicit
Const cListFile As String = "Defined Name Lists.xls" ' the file containing the combobox data
Const cListSheet As String = "JobName" ' the worksheet containing the list
Const cNameColumn As String = "a" ' the column containin gthe list data
Const cJobColumn As String = "b"
Const cHasHeader As Boolean = False ' does the list have a header in row 1
Private Sub UserForm_Initialize()
' open the workbook containing the data to load in combox1 read only
' and hide it
Dim iRow As Long
Dim wb As Workbook
Dim ws As Worksheet
Set wb = Workbooks("Defined Name Lists.xls")
Set ws = wb.Worksheets("JobName")
ws.Range("A2").Value = txtJobName.Text
Set theWB = Workbooks.Open(Filename:="Defined Name Lists.xls", ReadOnly:=True)
theWB.Windows(1).Visible = False
' address the combox list
Dim theSheet As Worksheet
Set theSheet = theWB.Worksheets(cListSheet)
' array size counter
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Dim nList As Long
nList = 0
' loop through all of the list loading the values into the combobox
Dim rw As Range
For Each rw In theSheet.Rows
' skip row 1 if there is a header
If (rw.Row = 1 And cHasHeader) Then
' stop on the first blank cell
ElseIf (rw.Cells(1, 1).Value = "") Then
Exit For
Else
' move the data from the list workbook to the combox
cboJobName.AddItem rw.Cells(1, 1).Value
' retain the job name and job no
nList = nList
ReDim Preserve Name(1 To nList)
ReDim Preserve Job(1 To nList)
Names(nList) = rw.Cells(1, cNameColumn).Value
Jobs(nList) = rw.Cells(1, cJobColumn).Value
End If
Next rw
' close the workbook and release storage
theWB.Close SaveChanges:=False
Set theWB = Nothing
Set theSheet = Nothing
End Sub