title: VBA macro dynamically created Scrollbar updates dynamically created Textbox
body: <p>How can a <strong>dynamically created Textbox</strong> be updated by a <strong>dynamically created Scrollbar</strong> using <code>WithEvents</code> handler? I have this userform code below and the Class Module thereafter.</p>
  
  <pre><code>Option Explicit
  
  Dim TextArray() As New Class1
  Dim ScrollArray() As New Class1
  
  
  Private Sub UserForm_Initialize()
      Dim ctlScroll As MSForms.ScrollBar
      Dim ctlText As MSForms.TextBox
  
      Dim ScrollTop As Long, i As Long
  
      '~~&gt; Decide on the .Top for the 1st TextBox
      ScrollTop = 10
  
  
  
      For i = 1 To 10
          Set ctlScroll = Me.Controls.Add("forms.ScrollBar.1", "ScrollBar" &amp; i)
          With ctlScroll
              .Left = 100
              .Top = ScrollTop
              .Width = 65
              .Height = 18
              .Orientation = fmOrientationHorizontal
              .Min = 1
              .Max = 5
          End With
  
          Set ctlText = Me.Controls.Add("forms.TextBox.1", "TextBox" &amp; i)
          With ctlText
              .Left = 40
              .Top = ScrollTop
              .Width = 50
              .Height = 18
              .MultiLine = False
              .MaxLength = 3
          End With
  
          ScrollTop = ScrollTop + 20
          ReDim Preserve ScrollArray(1 To i)
          Set ScrollArray(i).ScrollEvents = ctlScroll
          ReDim Preserve TextArray(1 To i)
          Set TextArray(i).TextEvents = ctlText
  
      Next i
  
  
  End Sub
  </code></pre>
  
  <p>This is the Class Module for the Events Handler</p>
  
  <pre><code>Public WithEvents ScrollEvents As MSForms.ScrollBar
  Public WithEvents TextEvents As MSForms.TextBox
  
  
  Private Sub ScrollEvents_Scroll()
      TextEvents.Value = ScrollEvents.Value
  End Sub
  </code></pre>