03856me
Active Member
- Joined
- Apr 4, 2008
- Messages
- 297
Excel 2007 Combo Box data find problem:
I have built a userform with two combo boxes. Both are pointing to tables, but the tables are on different worksheets. On my initialization event how do I set the worksheet for the second table? Is there a way to write the code and not have to specify the worksheet if you are using Arrays? This seems so simple but after two hours searching I need help!
foresterTable is on the worksheet called "lookups"
contractorsTable is on the worksheet called "tblContractors"
Here is the code I have so far but it is giving me this error "Run-time error '1004' Method 'Range' of object '_Worksheet' failed:
'---------------------------------------------------------------------
Private Sub UserForm_Initialize()
Dim myForester As Range
Dim ws As Worksheet
Set ws = Worksheets("lookups")
For Each myForester In ws.Range("foresterTable[Forester]")
With Me.cbo_forester
.AddItem myForester.Value
End With
Next myForester
Dim myContractor As Range
For Each myContractor In ws.Range("contractorTable[Contractors]")
With Me.cbo_contractor
.AddItem myContractor.Value
End With
Next myContractor
End Sub
'---------------------------------------------------------------------
I have built a userform with two combo boxes. Both are pointing to tables, but the tables are on different worksheets. On my initialization event how do I set the worksheet for the second table? Is there a way to write the code and not have to specify the worksheet if you are using Arrays? This seems so simple but after two hours searching I need help!
foresterTable is on the worksheet called "lookups"
contractorsTable is on the worksheet called "tblContractors"
Here is the code I have so far but it is giving me this error "Run-time error '1004' Method 'Range' of object '_Worksheet' failed:
'---------------------------------------------------------------------
Private Sub UserForm_Initialize()
Dim myForester As Range
Dim ws As Worksheet
Set ws = Worksheets("lookups")
For Each myForester In ws.Range("foresterTable[Forester]")
With Me.cbo_forester
.AddItem myForester.Value
End With
Next myForester
Dim myContractor As Range
For Each myContractor In ws.Range("contractorTable[Contractors]")
With Me.cbo_contractor
.AddItem myContractor.Value
End With
Next myContractor
End Sub
'---------------------------------------------------------------------