Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Select Case in ComboBox

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select Case in ComboBox

Maybe...

Private Sub ComboBox1_click()
Dim refrange As Range
dim c as range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

Brian wrote:

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Select Case in ComboBox

Thanks for the quick response.

Tried but failed. Am I right in assuming that the ListBox.AddItem will
result in the creation of the ListBox? The ComoBox was created in the code;

Private Sub UserForm_Initialize()
Dim myrange As Range

Set myrange = Sheets("GSOPs").Range("A4:A40")

For Each c In myrange
ComboBox1.AddItem c.Value
Next
End Sub
Private Sub ComboBox1_click()
Dim refrange As Range
Dim c As Range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

--
Brian McCaffery


"Dave Peterson" wrote:

Maybe...

Private Sub ComboBox1_click()
Dim refrange As Range
dim c as range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

Brian wrote:

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Select Case in ComboBox

Dave,
Ignore previous post, sorted it out.
Thanks for your help. The final problem was down to (my) finger trouble.
--
Brian McCaffery


"Brian" wrote:

Thanks for the quick response.

Tried but failed. Am I right in assuming that the ListBox.AddItem will
result in the creation of the ListBox? The ComoBox was created in the code;

Private Sub UserForm_Initialize()
Dim myrange As Range

Set myrange = Sheets("GSOPs").Range("A4:A40")

For Each c In myrange
ComboBox1.AddItem c.Value
Next
End Sub
Private Sub ComboBox1_click()
Dim refrange As Range
Dim c As Range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

--
Brian McCaffery


"Dave Peterson" wrote:

Maybe...

Private Sub ComboBox1_click()
Dim refrange As Range
dim c as range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

Brian wrote:

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select Case in ComboBox

Nope. .additem adds more items to an existing listbox.

You can add the listbox in your code (too much work though).

Or you can just design your form with the listbox already there. If you don't
want it to show when you start, you can can start with:

me.listbox1.visible = false

And decide to show it later with

me.listbox1.visible = true

The code you shared didn't create the combobox. It just added items to the
existing combobox.

======
Could it be that the value in the combobox isn't GSOP_286.

maybe...

Select Case lcase(trim(ComboBox1.Value))
Case lcase("GSOP_286")

to guard against leading/trailing spaces and lower case letters?????



Brian wrote:

Thanks for the quick response.

Tried but failed. Am I right in assuming that the ListBox.AddItem will
result in the creation of the ListBox? The ComoBox was created in the code;

Private Sub UserForm_Initialize()
Dim myrange As Range

Set myrange = Sheets("GSOPs").Range("A4:A40")

For Each c In myrange
ComboBox1.AddItem c.Value
Next
End Sub
Private Sub ComboBox1_click()
Dim refrange As Range
Dim c As Range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

--
Brian McCaffery

"Dave Peterson" wrote:

Maybe...

Private Sub ComboBox1_click()
Dim refrange As Range
dim c as range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

Brian wrote:

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select Case in ComboBox

I didn't see this followup. Ignore my other reply <vbg.

Brian wrote:

Dave,
Ignore previous post, sorted it out.
Thanks for your help. The final problem was down to (my) finger trouble.
--
Brian McCaffery

"Brian" wrote:

Thanks for the quick response.

Tried but failed. Am I right in assuming that the ListBox.AddItem will
result in the creation of the ListBox? The ComoBox was created in the code;

Private Sub UserForm_Initialize()
Dim myrange As Range

Set myrange = Sheets("GSOPs").Range("A4:A40")

For Each c In myrange
ComboBox1.AddItem c.Value
Next
End Sub
Private Sub ComboBox1_click()
Dim refrange As Range
Dim c As Range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

--
Brian McCaffery


"Dave Peterson" wrote:

Maybe...

Private Sub ComboBox1_click()
Dim refrange As Range
dim c as range
Select Case ComboBox1.Value
Case "GSOP_286"
'no .value and no .select
Set refrange = Sheets("Data").Range("A3:A20")
For Each c In refrange
ListBox1.AddItem c.Value
Next c
End Select
End Sub

Brian wrote:

I have a combobox from which, when the user selects an item, I want it to
find the data within a range, and use it to populate a ListBox. For the life
of me, I can't seem to figure it out. Any thoughts would be appreciated as
this is my first attempt at using Excel VBA. The code I have so far is:
(there is more than one case statement, but one should suffice for pointers.)

Private Sub ComboBox1_click()
Dim refrange As Range
Select Case ComboBox1.Value
Case "GSOP_286"
Set refrange = Sheets("Data").Range("A3:A20").Value.Select
For Each c In refrange
ListBox1.AddItem c.Value
Next
End Select
End Sub

Thanks,

--
Brian McCaffery

--

Dave Peterson


--

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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Case Select Jimbola Excel Programming 11 December 11th 05 06:45 PM
Need help on Select Case Susan Hayes Excel Worksheet Functions 1 November 3rd 04 10:25 PM


All times are GMT +1. The time now is 09:46 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"