ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Same event procedure for multiple controls (https://www.excelbanter.com/excel-programming/279408-same-event-procedure-multiple-controls.html)

Mikhail

Same event procedure for multiple controls
 
I have a userform with 18 TextBoxes. Their values are read from a worksheet.
On KeyPress event I write data back to worksheet.
Is it possible to write a procedure which accepts textbox control as
parameter as runs the same On_KeyPress sub for all 18 TextBoxes?
Or may be when KeyPress event is occurred on a form, is it possible to
determine which TextBox is active and do necessary actions on this TextBox?

Thanks in advance, Mike510



Tom Ogilvy

Same event procedure for multiple controls
 
You can use the technique documented by John Walkenbach:

http://j-walk.com/ss/excel/tips/tip44.htm
Handle Multiple UserForm Buttons With One Subroutine

This uses commandbuttons, but can be adapted for textboxes. Note that only
the events specific to the control can be handled this way. Events, such as
the exit event, inherited from the control object, can not be handled this
way.

It sounds like your textboxes are linked to cells, however. The link is a
two way street - if you make an entry in the textbox, it is also placed in
the linked cell. - make sure you are not fighting yourself, so to speak.

--
Regards,
Tom Ogilvy


"Mikhail" wrote in message
...
I have a userform with 18 TextBoxes. Their values are read from a

worksheet.
On KeyPress event I write data back to worksheet.
Is it possible to write a procedure which accepts textbox control as
parameter as runs the same On_KeyPress sub for all 18 TextBoxes?
Or may be when KeyPress event is occurred on a form, is it possible to
determine which TextBox is active and do necessary actions on this

TextBox?

Thanks in advance, Mike510






All times are GMT +1. The time now is 12:20 PM.

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