![]() |
many similar event procedures
I have written a macro, which contains many userform. each userform
contains many comboboxes (in addition to may other controls) I want several things to happen when the value in the combobox is changed. Here is an example of the code that i currently have in the combobox change event procedu Private Sub ComboBox10_Change() Dim ftype As Integer Recalc ftype = 2 + ComboBox10.ListIndex Call PriceToCell(12, ComboBox10, 20, ftype) End Sub Private Sub ComboBox11_Change() Dim ftype As Integer Recalc ftype = 2 + ComboBox11.ListIndex Call PriceToCell(12, ComboBox11, 18, ftype) End Sub etc.... I repeat this code many times where everything is almost exactly the same, except for the text "ComboBox10" would be the name of the combobox, and the the text "20" is specific for each combobox. what i would like to do is make this code generic so that i can copy it everywhere i need it without having to change it everytime, or even better refer to a procedure in my main module call..... so my first idea is initializing the combobox so that the value of combobox.tag in this case would be 20. Then i could replace the text 20, which is specific with something like Cint(ComboBox10.tag). But i still need to find some way to replace the specific ComboBox name, not in the name of the procedure, but only within the procedure. I have some idea that there is a solution to this involving setting up a class module, but i am not sure that i understand all the complexity of that. I thought the generic "Me" might work, but that gives me an error. any advice you have would be a big help. |
many similar event procedures
I guess i should have indicated something about the PriceToCell
function. it looks like this: Public Sub PriceToCell(ByVal cellpos As Integer, ByVal mycontrol As Object, ByVal wType As Integer, ByVal Fintype As Integer) Dim Price As Integer WindowPrice = Price(wType, finType) ActiveCell.Offset(0, cellpos).Value = mycontrol.Name & ":" & mycontrol.Value & ":" & Price End Sub |
All times are GMT +1. The time now is 05:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com