Load data from worksheet into Userform

Nitehawkhp

New Member
Joined
Dec 2, 2016
Messages
37
I have a column of data in a worksheet and need to load that data into text boxes on a userform.
I have done this in the past, however, I can’t get the code to work in this new situation.

A sample of the worksheet data consists of the following:

[TABLE="class: grid, width: 200"]
<tbody>[TR]
[TD]Row[/TD]
[TD]Description[/TD]
[TD]Yes/No[/TD]
[TD]Distance[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Vendor[/TD]
[TD] User Response[/TD]
[TD] User Response[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Category[/TD]
[TD] User Response[/TD]
[TD] User Response[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Series[/TD]
[TD] User Response[/TD]
[TD] User Response[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Orientation[/TD]
[TD] User Response[/TD]
[TD] User Response[/TD]
[/TR]
</tbody>[/TABLE]

I need a macro that will transfer the data into Userform

The Description column will be loaded into TextBoxes on a Userform called:

Textbox1
Textbox2
Textbox3
Textbox4

I have used the following code in a different worksheet and it works.

Code:
    Dim i As Integer
        Sheets("Players").Select
        Range("C2").Select
        ToCount = Range("G2")
    
        For i = 1 To ToCount
            Controls("Player" & i) = Cells(i + 1, 3)
        Next i

However, when I use it now I get a compile error
Sub or Function not defined

Code:
    Dim i As Integer
        Sheets("Data Validation").Select
        ToCount = Range("X1").Value
        
    
        For i = 1 To ToCount
            Controls("Data" & i) = Cells(i + 1, 3)
        Next i

I have changed the sheets name to match the new worksheet and,
range name for the data.

I have looked up controls and tried to figure out what was needed for that command, but
I don't understand.

Thanks for any help you can provide me.

Rod
 
Last edited:
And you have this code in a Button on your Useerform.

Why not show me all the code like.

Private Sub CommandButton1_Click()
And you code here
End Sub
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I suspect you do not have the sheet named exactly like this.
Or maybe the sheet is protected

Or Your Textbox does not have that exact name

Everything must be exact.
 
Upvote 0
Which line of code gets highlighted if you click debug?
The 424 error means that one of those textboxes doesn't exist.
 
Upvote 0
Mystery solved!!

I had the code under the area (I don't know if this is the correct terminology), on the userform it was placed under the "Click" area and not the "Initialize" area.
Once I moved the code to the initalize area it worked perfectly.

Happy to have this mess fixed.

Thank you to all who provided help and ideas to solve this mystery. Sleeping on it and having a fresh look at things allowed me to find the mistake.
Also, I looked at another userform and noticed the error.

Thanks again,

Rod
 
Upvote 0
Glad you sorted it out & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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