PDA

View Full Version : Solved: Run Time error 1004



tqm1
05-07-2007, 11:11 PM
Dear Experts

When I load userform, it shows following error message

Run Time error 1004
Select method of range class failed
May there is some worong in

Sub Load_Last_Entry()
Dim LastRow As Long
Sheets("Table").Cells(1, 1).Select
LastRow = Range("A65536").End(xlUp).Row 'find the last entry in Col A
MsgBox (Str(LastRow))
If LastRow > 1 Then
Me.TextBox1.Value = Sheets("Table").Cells(LastRow, 1).Value
Me.TextBox2.Value = Sheets("Table").Cells(LastRow, 2).Value
'.....
'.....
'.....
CurrentRow = LastRow
Sheets("Table").Cells(CurrentRow, 1).Select
End If
End Sub

The attachment is excel file, please reveiw and help to get rid of error message.

Thanks

jammer6_9
05-07-2007, 11:55 PM
It stops during Userform Initialize...


Private Sub UserForm_Initialize()
UserForm2.Caption = "Telephone Directory"
'Call Load_Last_Entry ---> Try removing this in your code
'Call total ---> Try removing this in your code

End Sub

tqm1
05-08-2007, 12:14 AM
You wrote
Try removing this in your code
But why? Because these two lines are not problem.
The problem is in procedure.

Charlize
05-08-2007, 12:15 AM
sheets.cellsis not a correct reference. First sheets.select and then cells.select. Attached a little revision of your coding. One tip, try to declare the variables that you want to use. That way you have to think about what the variable is supposed to hold.

Charlize

ps. I didn't looked at the rest. So I just adapted the coding to let the form show the first time. I believe there is still some work to be done to let this thing do what it is supposed to do (after a quick look at the rest).

tqm1
05-08-2007, 03:26 AM
Dear Sir,

When I hide sheets("Table") then again following error message appears

Run Time error 1004
Select method of range class failed

I want to use UserForm while hiding Sheet("Table")

Please modify your attachment file
Thanks

Charlize
05-08-2007, 03:41 AM
Dear Sir,

When I hide sheets("Table") then again following error message appears

Run Time error 1004
Select method of range class failed

I want to use UserForm while hiding Sheet("Table")

Please modify your attachment file
ThanksYou can't use select when hiding sheets. You can refer to a sheet and perform some actions on it even when its hidden but don't use select.

This means that you have to consider to change the way you are handling the form. You can use worksheets("Table").Range(...) to fill your form.

Charlize