LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Comboboxes

I want to create two comboboxes but i want the second one to show me only
relevant info from the first one.

For example

i have Australia,Usa for the first combobox
and the second one i want to show me only the cities of each country. So if
i choose australia i wish the second combobox to drop down only Sydney,
Perth

I wrote a code for this but something doesnot work in the second part..
Could anyone let me know what is wrong?

Thanks in advance

Angeliki


Option Explicit
Dim Data As Range
Dim LowestLevel As Long
Private Sub ComboBox1_click()

Dim rng As Range, cell As Range
Dim res As Variant
Dim varr() As String
Dim icnt As Long
Dim bFirst As Boolean
ReDim varr(1 To 50)
If ComboBox1.ListIndex < -1 Then
If LowestLevel 1 Then
Data.Parent.ShowAllData
End If
Worksheets("Database").Select
Worksheets("Database").AutoFilter.Range.AutoFilter Field:=1,
Criteria1:=ComboBox1.Value
LowestLevel = 2
ComboBox2.Clear
On Error Resume Next
Set rng = Data.Columns(2).SpecialCells(xlVisible)
On Error GoTo 0
bFirst = True
If rng Is Nothing Then
ComboBox2.Clear
Exit Sub
End If
End If
For Each cell In rng
If bFirst Then
ComboBox2.AddItem cell.Value
icnt = 1
varr(icnt) = cell.Value
bFirst = False
Else
res = Application.Match(cell.Value, varr, 0)
If IsError(res) Then
icnt = icnt + 1
varr(icnt) = cell.Value
ComboBox2.AddItem cell.Value
If icnt = UBound(varr) Then _
ReDim Preserve varr(1 To UBound(varr) + 50)
End If
End If
Next
ComboBox2.Clear
ComboBox2.ListIndex = -1
End Sub
Private Sub ComboBox2_click()
Dim rng As Range, cell As Range
Dim res As Variant
Dim varr() As String
Dim icnt As Long
Dim bFirst As Boolean
ReDim varr(1 To 50)
If ComboBox1.ListIndex < -1 Then
If LowestLevel 2 Then
Data.Parent.ShowAllData
Worksheets("Database").AutoFilter.Range.AutoFilter Field:=1, _
Criteria1:=ComboBox1.Value
End If
Worksheets("Database").AutoFilter.Range.AutoFilter Field:=2, _
Criteria1:=ComboBox2.Value
' Worksheets("Database").AutoFilter.Range _
' .AutoFilter Field:=3, _
' Criteria1:=ComboBox3.Value
LowestLevel = 2
Else
ComboBox2.Clear
ComboBox2.ListIndex = -1
End If
End Sub

Private Sub CommandButton1_Click()

Application.ScreenUpdating = False

Worksheets("Database").Select
Worksheets("Database").Cells(1, 1).Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Worksheets("Catastrophes").Select
Cells(1, 11).Select
ActiveSheet.Paste
Cells(1, 1).Select
Application.CutCopyMode = True

Unload UserForm1

End Sub

Private Sub UserForm_Initialize()
Dim rng As Range

With Worksheets("info")
Set rng = .Cells(1, 1).CurrentRegion.Columns(1)
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
End With
ComboBox1.RowSource = rng.Address(external:=True)
With Worksheets("Database")
Set rng = .Cells(1, 1).CurrentRegion
If Not .AutoFilterMode Then
rng.AutoFilter
Else
If .FilterMode Then
.ShowAllData
End If
End If
Set Data = .AutoFilter.Range
Set Data = Data.Offset(1, 0).Resize( _
Data.Rows.Count - 1)
End With
End Sub






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
comboboxes [email protected] uk Excel Discussion (Misc queries) 1 December 6th 09 05:07 PM
Comboboxes mr-bear New Users to Excel 1 November 21st 06 10:05 AM
Need help with ComboBoxes. rosemary New Users to Excel 2 July 9th 05 12:19 AM
ComboBoxes and Formulas excel user Excel Programming 2 October 1st 03 01:57 PM
Comboboxes David W[_3_] Excel Programming 1 August 29th 03 11:13 PM


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"