#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default ComboBox

Hi all,

Excel 2003
I have a combo box named cboCategory.
After selecting an item from the list, that item remains "active" and can't
be selected next time.
I've tried adding cboCategory.ListIndex = -1 but this causes an error, as
follows.

Run-time Error 381
Could not get the Column property. Invalid property array index

The code used is as follows:

Private Sub CboCategory_Change()
Application.EnableEvents = False
ActiveCell = CboCategory.Column(1)
ActiveCell.Offset(0, -1) = CboCategory.Column(0)
ActiveCell.Select
Application.EnableEvents = True
End Sub

Any pointers ?
Thanks and regards,
Don


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default ComboBox

I'm guessing that you have a combobox from the control toolbox toolbar on the
worksheet.

This worked for me:

Option Explicit
Dim BlkProc As Boolean
Private Sub CboCategory_Change()
If BlkProc Then Exit Sub
Application.EnableEvents = False
ActiveCell = cboCategory.Column(1)
ActiveCell.Offset(0, -1) = cboCategory.Column(0)
ActiveCell.Offset(1, 0).Select
BlkProc = True
'cboCategory.Value = ""
'or
cboCategory.ListIndex = -1
BlkProc = False
Application.EnableEvents = True
End Sub

The application.enableevents will stop the worksheet_change event from firing
when you change values--but when you change the .listindex to -1, .enableevents
won't stop the cbocategory_change event from firing.

You have to control that yourself.

A typical method is to use a boolean variable and toggle it and check it when
you need to (blkProc was my boolean variable).



Don Lloyd wrote:

Hi all,

Excel 2003
I have a combo box named cboCategory.
After selecting an item from the list, that item remains "active" and can't
be selected next time.
I've tried adding cboCategory.ListIndex = -1 but this causes an error, as
follows.

Run-time Error 381
Could not get the Column property. Invalid property array index

The code used is as follows:

Private Sub CboCategory_Change()
Application.EnableEvents = False
ActiveCell = CboCategory.Column(1)
ActiveCell.Offset(0, -1) = CboCategory.Column(0)
ActiveCell.Select
Application.EnableEvents = True
End Sub

Any pointers ?
Thanks and regards,
Don


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ComboBox

Private Sub CboCategory_MouseDown(ByVal Button _
As Integer, ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
cboCategory.ListIndex = -1
End Sub

--
Regards,
Tom Ogilvy


"Don Lloyd" wrote in message
...
Hi all,

Excel 2003
I have a combo box named cboCategory.
After selecting an item from the list, that item remains "active" and

can't
be selected next time.
I've tried adding cboCategory.ListIndex = -1 but this causes an error,

as
follows.

Run-time Error 381
Could not get the Column property. Invalid property array index

The code used is as follows:

Private Sub CboCategory_Change()
Application.EnableEvents = False
ActiveCell = CboCategory.Column(1)
ActiveCell.Offset(0, -1) = CboCategory.Column(0)
ActiveCell.Select
Application.EnableEvents = True
End Sub

Any pointers ?
Thanks and regards,
Don




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
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
Combobox N.F[_2_] Excel Discussion (Misc queries) 2 August 17th 07 02:05 AM
combobox changes value flow23 Excel Discussion (Misc queries) 0 May 11th 06 04:44 PM
Combobox David Fixemer Excel Programming 1 February 24th 04 05:03 AM
Combobox Scott Excel Programming 2 July 23rd 03 02:49 PM


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