Hi,
I'm trying to create a Userform with TextBox1 already there. I have a table of data and need to apply the filter for a specific value and then add textboxes as per the count of filtered values. In each text box, needs the value of the cell next in the column. Here's my code.
Private Sub CommandButton1_Click()
Selection.AutoFilter
Range("F1").Select
ActiveSheet.Range("$A$1:$I$14").AutoFilter Field:=6, Criteria1:=TextBox1.Value
Range("F1").Select
Dim cCntrl As Control
Dim b As Range
Dim c As Integer
Set b = Range("A:A")
Range("AZ1").Value = WorksheetFunction.Subtotal(3, b)
For a = 1 To Range("AZ1").Value - 1
Set c = WorksheetFunction.Sum(a, 1)
Set cCntrl = Me.Controls.Add("Forms.TextBox." & c, "MyTextBox", True)
With cCntrl
.Width = 150
.Height = 15
.Top = 10 * 2 * a
.Left = 10
.ZOrder (0)
End With
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
TextBox& c.Value = ActiveCell.Value
Next a
Selection.AutoFilter
End Sub
I'm getting an error "Object Required" for "Set c = a + 1"
Not able to understand why. Please help!
I'm trying to create a Userform with TextBox1 already there. I have a table of data and need to apply the filter for a specific value and then add textboxes as per the count of filtered values. In each text box, needs the value of the cell next in the column. Here's my code.
Private Sub CommandButton1_Click()
Selection.AutoFilter
Range("F1").Select
ActiveSheet.Range("$A$1:$I$14").AutoFilter Field:=6, Criteria1:=TextBox1.Value
Range("F1").Select
Dim cCntrl As Control
Dim b As Range
Dim c As Integer
Set b = Range("A:A")
Range("AZ1").Value = WorksheetFunction.Subtotal(3, b)
For a = 1 To Range("AZ1").Value - 1
Set c = WorksheetFunction.Sum(a, 1)
Set cCntrl = Me.Controls.Add("Forms.TextBox." & c, "MyTextBox", True)
With cCntrl
.Width = 150
.Height = 15
.Top = 10 * 2 * a
.Left = 10
.ZOrder (0)
End With
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
TextBox& c.Value = ActiveCell.Value
Next a
Selection.AutoFilter
End Sub
I'm getting an error "Object Required" for "Set c = a + 1"
Not able to understand why. Please help!