Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default ListBox List Code?

I have combobox1, combobox2 and listbox1.

i am runnig the code from sheet1

in my below code only for the first item column 2 and
three are displyed..

also how can I use dynamic range?

is it possible to get unique item from sheet2 Range(Range
("A2"),Range("A65536").end(xlup)) as combobox1 list?



Private Sub ComboBox1_Change()

Dim sh As Worksheet
Dim cell As Range

Me.ListBox1.Clear

Set sh = Sheets("sheet2")

For Each cell In sh.Range("a2:a10")
If cell.Value = Me.ComboBox1.Value And cell.Offset(0,
2).Value = ComboBox2.Value Then
'If cell.Offset(0, 2).Value = ComboBox2.Value Then
Me.ListBox1.AddItem cell.Value
Me.ListBox1.List(0, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(0, 2) = cell.Offset(0, 2).Value
'End If
End If
Next cell

End Sub

Private Sub ComboBox2_Change()

Dim sh As Worksheet
Dim cell As Range

Me.ListBox1.Clear

Set sh = Sheets("sheet2")

For Each cell In sh.Range("a2:a10")
If cell.Value = Me.ComboBox1.Value And cell.Offset(0,
2).Value = ComboBox2.Value Then
'If cell.Offset(0, 2).Value = ComboBox2.Value Then
Me.ListBox1.AddItem cell.Value
Me.ListBox1.List(0, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(0, 2) = cell.Offset(0, 2).Value
'End If
End If
Next cell

End Sub


Thanks for your help..

Abdul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default ListBox List Code?

You're updating the 2nd and third columns of the first entry with these lines:

Me.ListBox1.List(0, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(0, 2) = cell.Offset(0, 2).Value


Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = cell.Offset(0, 2).Value

To save typing:
With Me.ListBox1
.AddItem cell.Value
.List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
.List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
End With

And John Walkenbach shows a technique for getting a unique list into a
listbox--you can use the same kind of thing for your combobox.

http://j-walk.com/ss/excel/tips/tip47.htm



Abdul wrote:

I have combobox1, combobox2 and listbox1.

i am runnig the code from sheet1

in my below code only for the first item column 2 and
three are displyed..

also how can I use dynamic range?

is it possible to get unique item from sheet2 Range(Range
("A2"),Range("A65536").end(xlup)) as combobox1 list?

Private Sub ComboBox1_Change()

Dim sh As Worksheet
Dim cell As Range

Me.ListBox1.Clear

Set sh = Sheets("sheet2")

For Each cell In sh.Range("a2:a10")
If cell.Value = Me.ComboBox1.Value And cell.Offset(0,
2).Value = ComboBox2.Value Then
'If cell.Offset(0, 2).Value = ComboBox2.Value Then
Me.ListBox1.AddItem cell.Value
Me.ListBox1.List(0, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(0, 2) = cell.Offset(0, 2).Value
'End If
End If
Next cell

End Sub

Private Sub ComboBox2_Change()

Dim sh As Worksheet
Dim cell As Range

Me.ListBox1.Clear

Set sh = Sheets("sheet2")

For Each cell In sh.Range("a2:a10")
If cell.Value = Me.ComboBox1.Value And cell.Offset(0,
2).Value = ComboBox2.Value Then
'If cell.Offset(0, 2).Value = ComboBox2.Value Then
Me.ListBox1.AddItem cell.Value
Me.ListBox1.List(0, 1) = cell.Offset(0, 1).Value
Me.ListBox1.List(0, 2) = cell.Offset(0, 2).Value
'End If
End If
Next cell

End Sub

Thanks for your help..

Abdul


--

Dave Peterson

Reply
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
copying the contents of a drop down list from the listbox itself? Digi777 Excel Discussion (Misc queries) 0 January 25th 10 10:06 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
DONT WANT TO SEE LISTBOX SELEXTED ITEMS WHEN COME BACK TO LIST BOX CAPTGNVR Excel Discussion (Misc queries) 0 January 29th 07 08:44 PM
Create ListBox (?) same as Find all Result List Soniya Excel Programming 1 October 2nd 03 01:22 PM
Excel; vba; listbox how to reorganize list in alfabetical order Konrad Excel Programming 1 August 7th 03 03:50 AM


All times are GMT +1. The time now is 12:05 AM.

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

About Us

"It's about Microsoft Excel"