Loop through text boxes in a page

chroniclesofdave

New Member
Joined
Aug 8, 2016
Messages
48
Ok, I have working code that looks like this:
Code:
Private Sub CommandButton39_Click()
Dim objWorkbook As Workbook
Dim i As Integer
Dim arrIn As Variant
Dim arrOut()
Dim j As Long
Dim counter As Long
Dim outRow As Long
Dim sUser As String
Set objWorkbook = Workbooks.Open( _
"C:\Documents\Data.xlsm")
sUser = "user1"
With Sheets("Final").Range("A1").CurrentRegion
    arrIn = .Value
    counter = Application.CountIf(.Columns(2), sUser)
    ReDim arrOut(1 To counter)
    outRow = 1
    For i = 1 To UBound(arrIn)
        If VBA.LCase$(arrIn(i, 2)) = sUser Then
            For j = 1 To UBound(arrIn, 2) - 1
                arrOut(outRow) = arrOut(outRow) & arrIn(i, j) & vbTab
            Next j
            arrOut(outRow) = arrOut(outRow) & arrIn(i, j)
            outRow = outRow + 1
        End If
    Next i
    objWorkbook.Close SaveChanges:=False
    With TextBox4
        .MultiLine = True
        .Value = Join(arrOut, vbCrLf)
        End With
    End With
    On Error Resume Next
End Sub

And it works great, but I am trying to have each copied cells data paste into a different textbox in page 1 of the user form. So far I have this:

Code:
Private Sub CommandButton39_Click()
Dim objWorkbook As Workbook
Dim i As Integer
Dim arrIn As Variant
Dim arrOut()
Dim j As Long
Dim counter As Long
Dim outRow As Long
Dim sUser As String
Set objWorkbook = Workbooks.Open( _
"C:\Documents\Data.xlsm")
sUser = "user1"

With Sheets("Final").Range("A1").CurrentRegion
    arrIn = .Value
    counter = Application.CountIf(.Columns(2), sUser)
    For i = 1 To UBound(arrIn)
        If VBA.LCase$(arrIn(i, 2)) = sUser Then
            For j = 1 To UBound(arrIn, 2) - 1
               outRow = outRow + 1
               Me.Controls("textbox" & outRow) = arrIn(i, j)
            Next j
        End If
    Next i
   objWorkbook.Close SaveChanges:=False
        End With
    On Error Resume Next
End Sub
But the code keeps throwing an error on
Code:
Me.Controls("textbox" & outRow) = arrIn(i, j)
The error is "Run-time error '-2147024809 (80070057': Could not find the specified object." I keep hitting my head on the desk to jar an idea, and i know it probably had to do with the page1 not being cited, but i can't figure out how to incorporate it. any help is appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
What is the value of counter & outrow when you get the error?
Also how many columns are there in you data & how many textboxes do you have?
 
Upvote 0
When the error occurs click Debug, then hover the cursor over outrow, you should see the value of outrow, what is it?
 
Upvote 0
In that case you don't have a textbox called textbox1, have you renamed them?
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top