Syntax Error for Load Me()

excelenergy

Board Regular
Joined
Jun 7, 2012
Messages
142
Hello,

I got fairly easy problem one of you may know the answer too. I just couldn't figure out.

I have a userform, when its triggered, text boxes get populated. The data in the text boxes are coming from cell values in another sheet.

However when I execute my Macro in the other sheet where the values are, the text boxes load up.
When I execute my Macro in the sheet its supposed to be executed in. The text boxes don't load up.

Any idea why this is? Id like to change the syntax so its point at the right sheet, but everything Ive tried doesn't work, here is an example

Code:
Sub LoadBoxes()
'/// if you use a With Statement then the control needs prefixing with .
    With Me
    
Worksheets("Sheet1 (4)").txtNumber.Value = Cells(currentrow, 1).Text
        .txtName.Value = Cells(currentrow, 2).Text
        .TextBox1.Value = Cells(currentrow, 6).Text
        .TextBox2.Value = Cells(currentrow, 5).Text
        .txtCreator.Value = Cells(currentrow, 7).Text
        .txtOwner.Value = Cells(currentrow, 3).Text
        .txtYears.Value = Cells(currentrow, 10).Text
        .ListBox1.Value = Cells(currentrow, 8).Text
        .TextBox3.Value = Cells(currentrow, 9).Text
    End With
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is "currentrow" is that a variable?
` Cells(currentrow, 2).Text` will only work for the active sheet, so loading the userform in when the active sheet has the data, it will load the correct values. You need to indicate what sheet you want the values from

Code:
Dim ws As Worksheet
Set ws = Sheets("Sheet1")    ' whatever the sheet name is with the data

Worksheets("Sheet1 (4)").txtNumber.Value = Cells(currentrow, 1).Text
.txtName.Value = ws.Cells(currentrow, 2).Text
.TextBox1.Value = ws.Cells(currentrow, 6).Text
.TextBox2.Value = ws.Cells(currentrow, 5).Text
.txtCreator.Value = ws.Cells(currentrow, 7).Text

etc....
 
Last edited:
Upvote 0
Oh, I didn't even catch that. Ill alter it to the correct sheet.

Thanks!


What is "currentrow" is that a variable?
` Cells(currentrow, 2).Text` will only work for the active sheet, so loading the userform in when the active sheet has the data, it will load the correct values. You need to indicate what sheet you want the values from

Code:
Dim ws As Worksheet
Set ws = Sheets("Sheet1")    ' whatever the sheet name is with the data

Worksheets("Sheet1 (4)").txtNumber.Value = Cells(currentrow, 1).Text
.txtName.Value = ws.Cells(currentrow, 2).Text
.TextBox1.Value = ws.Cells(currentrow, 6).Text
.TextBox2.Value = ws.Cells(currentrow, 5).Text
.txtCreator.Value = ws.Cells(currentrow, 7).Text

etc....
 
Upvote 0

Forum statistics

Threads
1,224,761
Messages
6,180,818
Members
452,997
Latest member
gimamabe71

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