Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to populate a combobox based on selection from another combobo

Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.

Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?

I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to populate a combobox based on selection from anothercombobo

On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.

Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?

I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.

Thanks.


Hi LinnT,

The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfiles.html#DataVal uses existing Excel
functions to achieve this dependency.

Regards
trevosef
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to populate a combobox based on selection from another com

Hi Trevosef,

Thanks! It was a big help.

I have another question.
Once I have made a selection in combobox1 and combobox2, when I reselected
another item from combobox1, the combobox2 still show the last selected value
which might not be very "friendly". How do I set combobox2 to blank when I do
a reselection from combobox1?

Regards.

" wrote:

On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.

Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?

I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.

Thanks.


Hi LinnT,

The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfiles.html#DataVal uses existing Excel
functions to achieve this dependency.

Regards
trevosef

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to populate a combobox based on selection from another com

On Nov 22, 12:55 pm, LinnT wrote:
Hi Trevosef,

Thanks! It was a big help.

I have another question.
Once I have made a selection in combobox1 and combobox2, when I reselected
another item from combobox1, the combobox2 still show the last selected value
which might not be very "friendly". How do I set combobox2 to blank when I do
a reselection from combobox1?

Regards.



" wrote:
On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.


Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?


I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.


Thanks.


Hi LinnT,


The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfiles.html#DataValuses existing Excel
functions to achieve this dependency.


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,

Try it this works. Open VBE (Press Alt+F11). Double-click on Sheet1
(the sheet with the validation combo boxes). Then, Copy and Paste the
following code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Dim rngCountry As Range
Dim rngCity As Range
Set rngCountry = Sheet1.Range("B3")
Set rngCity = Sheet1.Range("C3")
If Target.Address = rngCountry.Address Then
If Not IsEmpty(rngCity) Then
rngCity.Value = ""
End If
End If
End Sub

The above assumes that country is specified in cell B3 and city in
cell C3. Double-click on country (B3) should clear the value in city
(C3).

Regards
trevosef
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to populate a combobox based on selection from another com

Hi Trevosef,

The script does not really do what I wanted. Instead of double-click I was
actually thinking of on selectionchange of the combobox1.
Nevertheless, thanks for the suggestion. :)

Best Regards.

" wrote:

On Nov 22, 12:55 pm, LinnT wrote:
Hi Trevosef,

Thanks! It was a big help.

I have another question.
Once I have made a selection in combobox1 and combobox2, when I reselected
another item from combobox1, the combobox2 still show the last selected value
which might not be very "friendly". How do I set combobox2 to blank when I do
a reselection from combobox1?

Regards.



" wrote:
On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.


Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?


I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.


Thanks.


Hi LinnT,


The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfiles.html#DataValuses existing Excel
functions to achieve this dependency.


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,

Try it this works. Open VBE (Press Alt+F11). Double-click on Sheet1
(the sheet with the validation combo boxes). Then, Copy and Paste the
following code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Dim rngCountry As Range
Dim rngCity As Range
Set rngCountry = Sheet1.Range("B3")
Set rngCity = Sheet1.Range("C3")
If Target.Address = rngCountry.Address Then
If Not IsEmpty(rngCity) Then
rngCity.Value = ""
End If
End If
End Sub

The above assumes that country is specified in cell B3 and city in
cell C3. Double-click on country (B3) should clear the value in city
(C3).

Regards
trevosef



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to populate a combobox based on selection from another com

On Nov 23, 10:58 am, LinnT wrote:
Hi Trevosef,

The script does not really do what I wanted. Instead of double-click I was
actually thinking of on selectionchange of the combobox1.
Nevertheless, thanks for the suggestion. :)

Best Regards.



" wrote:
On Nov 22, 12:55 pm, LinnT wrote:
Hi Trevosef,


Thanks! It was a big help.


I have another question.
Once I have made a selection in combobox1 and combobox2, when I reselected
another item from combobox1, the combobox2 still show the last selected value
which might not be very "friendly". How do I set combobox2 to blank when I do
a reselection from combobox1?


Regards.


" wrote:
On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.


Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?


I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.


Thanks.


Hi LinnT,


The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfile...alusesexisting Excel
functions to achieve this dependency.


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,


Try it this works. Open VBE (Press Alt+F11). Double-click on Sheet1
(the sheet with the validation combo boxes). Then, Copy and Paste the
following code:


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Dim rngCountry As Range
Dim rngCity As Range
Set rngCountry = Sheet1.Range("B3")
Set rngCity = Sheet1.Range("C3")
If Target.Address = rngCountry.Address Then
If Not IsEmpty(rngCity) Then
rngCity.Value = ""
End If
End If
End Sub


The above assumes that country is specified in cell B3 and city in
cell C3. Double-click on country (B3) should clear the value in city
(C3).


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,

To clear the value in city combobox2, while in design mode, double-
click on the Country combobox1 to get to the code window. In the code
window, it should show combobox1 on the left box. Select the change
event on the right box. It should display:
Private sub combobox1_change()

'To clear city combobox2 when country combobox1 value is changed
combobox2 = ""

End Sub
The above code assumes that country is combobox1 and city is
combobox2.
Hope this helps

Regards
Trevosef





In the code window,
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default How to populate a combobox based on selection from another com

Thanks!

" wrote:

On Nov 23, 10:58 am, LinnT wrote:
Hi Trevosef,

The script does not really do what I wanted. Instead of double-click I was
actually thinking of on selectionchange of the combobox1.
Nevertheless, thanks for the suggestion. :)

Best Regards.



" wrote:
On Nov 22, 12:55 pm, LinnT wrote:
Hi Trevosef,


Thanks! It was a big help.


I have another question.
Once I have made a selection in combobox1 and combobox2, when I reselected
another item from combobox1, the combobox2 still show the last selected value
which might not be very "friendly". How do I set combobox2 to blank when I do
a reselection from combobox1?


Regards.


" wrote:
On Nov 22, 10:20 am, LinnT wrote:
Hi,
I have 2 combobox with data inside.
When I select an item (eg. x) from ComboBox1, I require ComboBox2 to
contain/filter only related items to x.


Can I confirm that I couldn't use any existing Excel functions to do that?
How do I do that with macro?


I tried to do that by creating a Form in macro and adding comboboxes to the
Form. However I would still prefer to do it in a worksheet.


Thanks.


Hi LinnT,


The example 'Dependent Lists Country City' in this website
http://www.contextures.com/excelfile...alusesexisting Excel
functions to achieve this dependency.


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,


Try it this works. Open VBE (Press Alt+F11). Double-click on Sheet1
(the sheet with the validation combo boxes). Then, Copy and Paste the
following code:


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)
Dim rngCountry As Range
Dim rngCity As Range
Set rngCountry = Sheet1.Range("B3")
Set rngCity = Sheet1.Range("C3")
If Target.Address = rngCountry.Address Then
If Not IsEmpty(rngCity) Then
rngCity.Value = ""
End If
End If
End Sub


The above assumes that country is specified in cell B3 and city in
cell C3. Double-click on country (B3) should clear the value in city
(C3).


Regards
trevosef- Hide quoted text -


- Show quoted text -


Hi LinnT,

To clear the value in city combobox2, while in design mode, double-
click on the Country combobox1 to get to the code window. In the code
window, it should show combobox1 on the left box. Select the change
event on the right box. It should display:
Private sub combobox1_change()

'To clear city combobox2 when country combobox1 value is changed
combobox2 = ""

End Sub
The above code assumes that country is combobox1 and city is
combobox2.
Hope this helps

Regards
Trevosef





In the code window,

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
Populate Adjacent Cells based on Pull Down Selection Ambassador New Users to Excel 0 June 29th 09 12:19 AM
Auto Populate Based on Other Selection Kate Excel Discussion (Misc queries) 2 May 15th 07 10:57 PM
How do i populate a text box according to selection in combobox? Steve Excel Worksheet Functions 0 April 13th 06 12:40 PM
Auto populate several cells based on a selection from drop down li Sheldon Excel Discussion (Misc queries) 3 January 13th 06 08:12 PM
Having data populate text boxes based on Combobox Value Todd Huttenstine[_2_] Excel Programming 1 November 10th 03 01:35 AM


All times are GMT +1. The time now is 03:54 PM.

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"