ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   combobox (https://www.excelbanter.com/excel-programming/336529-combobox.html)

MVM

combobox
 
I have 16 comboboxes on an excel sheet. When a change takes place, i want
some function to trigger. is there any way to write a generic function as an
event of 'change'. is there any way to identify the calling control?

thanks
MVM

K Dales[_2_]

combobox
 
There is no easy way around it: the comboboxes will only trigger their own
_change event, so they will all need their own event procedure to be
detected. If you needed to do this on a bigger scale, or planned to design
more workbooks with a similar feature, you could define a custom class with
its own events; but that would be a lot of work.

I have found the easiest way is to make a simple and easily copied and
modified event procedure to run and immediately call a "master" subroutine:

1) for the first combobox, write an event procedure like this:
Sub ComboBox1_Change()
Call ComboMain(1)
End Sub

2) Now copy this and paste the copy 15 times. Go to each, highlight it, and
do a Find/Replace (Ctrl H) to change 1 to 2, or 3, or 4, or 5, ... and so on
for each; e.g. the final one will look like this:

Sub ComboBox16_Change()
Call ComboMain(16)
End Sub

3) Now to tie it all together:
Sub ComboMain(CBNumber as Integer)
'CBNumber tells you which combobox was changed, so now do whatever you
need to do here
End Sub

It is not too bad to set up this way, and I think it can do what you want.
--
- K Dales


"MVM" wrote:

I have 16 comboboxes on an excel sheet. When a change takes place, i want
some function to trigger. is there any way to write a generic function as an
event of 'change'. is there any way to identify the calling control?

thanks
MVM



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com