Thanks Gary. It's great :-)
"Gary Keramidas" wrote:
you can try this, although i've renamed thing for simplicity on my end
Option Explicit
Public WithEvents textboxGroup As MSForms.TextBox
Private Sub textboxgroup_Change()
MsgBox "Hello from " & textboxGroup.Name
End Sub
================================
Option Explicit
Dim textboxes() As New Class1
Sub ShowDialog()
Dim ctrl As Control
Dim TextboxCount As Long, X As Long
TextboxCount = 0
X = 1
For Each ctrl In UserForm1.Controls
If X = 11 Then Exit For
If TypeName(ctrl) = "TextBox" Then
'If ctrl.Name < "OKButton" Then 'Skip the OKButton
TextboxCount = TextboxCount + 1
ReDim Preserve textboxes(1 To TextboxCount)
Set textboxes(TextboxCount).textboxGroup = ctrl
'End If
End If
X = X + 1
Next
UserForm1.Show
End Sub
--
Gary
"Sam Kuo" wrote in message
...
I tried to modify John Walkenbach's example in the link below (i.e. assigning
one subroutine to multiple buttons) to do the same task but for textboxes
instead of buttons:
http://www.j-walk.com/ss/excel/tips/tip44.htm
e.g. I have several textboxes, and I only want to assign a subroutine to 10
particular textboxes (namely txtCatch1PreY1 to txtCatch1PreY10). But my
attempt below seems to assign the subroutine to txtCatch1PreY1 only. Can
someone please help me spot where the problem is in my code?
' The following code is in Class Module 1
Public WithEvents SlopeTextboxGroup As MSForms.TextBox
Private Sub SlopeTextboxGroup_Change()
MsgBox "Hello from " & SlopeTextboxGroup.Name
End Sub
' The following code is in Module 1
Option Explicit
Dim TextBoxes() As New Class1
Sub ShowDialog()
Dim ctrl As Control
Dim TextboxCount As Integer
TextboxCount = 1
For Each ctrl In UserForm1.Controls
If TypeName(ctrl) = "TextBox" Then
If ctrl.Name = "txtCatch1PreY" & TextboxCount Then
TextboxCount = TextboxCount + 1
ReDim Preserve TextBoxes(1 To TextboxCount)
Set TextBoxes(TextboxCount).SlopeTextboxGroup = ctrl
End If
End If
Next ctrl
' Show UserForm1
UserForm1.Show
End Sub