LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Runtime Error 1004:Method 'Range' of object'_Worksheet' Failed

I have a s imple program that is executed from a button on an excel
spreadsheet. It is suppose to bring up a user form for the user to
enter data and save to a worksheet in the xls. I can't get it to
run. Here is all of the code:


Private Sub cmdAdd_Click()

Dim iRow As Long
Dim iPart As Long
Dim ws As Worksheet
Set ws = Worksheets("ASAPEngines")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
..End(xlUp).Offset(1, 0).Row

iPart = Me.cbostatus.ListIndex


'copy the data to the database
With ws
ws.Cells(iRow, 1).Value = Me.Iusername.Value
ws.Cells(iRow, 2).Value = Me.cbostatus.Value
ws.Cells(iRow, 3).Value = Me.Istore.Value
ws.Cells(iRow, 4).Value = Me.cbomake.Value
ws.Cells(iRow, 5).Value = Me.Imodel.Value
ws.Cells(iRow, 6).Value = Me.Itype.Value
ws.Cells(iRow, 7).Value = Me.Ienginemake.Value
ws.Cells(iRow, 8).Value = Me.Icilit.Value
ws.Cells(iRow, 9).Value = Me.Ifuel.Value
ws.Cells(iRow, 10).Value = Me.Iremarks.Value
ws.Cells(iRow, 11).Value = Me.Iserialnumber.Value
ws.Cells(iRow, 12).Value = Me.Iprice.Value
ws.Cells(iRow, 13).Value = Me.Icore.Value
ws.Cells(iRow, 14).Value = Me.Ihours.Value
ws.Cells(iRow, 15).Value = Me.Iopidle.Value
ws.Cells(iRow, 16).Value = Me.Iopft.Value
ws.Cells(iRow, 17).Value = Me.Iblockcasting.Value
ws.Cells(iRow, 18).Value = Me.Ilocation.Value
ws.Cells(iRow, 19).Value = Me.Istocknumber.Value
End With

'clear the data
Me.Iusername.Value = ""
Me.cbostatus.Value = ""
Me.Istore.Value = ""
Me.cbomake.Value = ""
Me.Imodel.Value = ""
Me.Itype.Value = ""
Me.Ienginemake.Value = ""
Me.Icilit.Value = ""
Me.Ifuel.Value = ""
Me.Iremarks.Value = ""
Me.Iserialnumber.Value = ""
Me.Iprice.Value = ""
Me.Icore.Value = ""
Me.Ihours.Value = ""
Me.Iopidle.Value = ""
Me.Iopft.Value = ""
Me.Iblockcasting.Value = ""
Me.Ilocation.Value = ""
Me.Istocknumber.Value = ""
Me.Iusername.SetFocus


End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub


Private Sub UserForm_Initialize()

Dim cStatus As Range
Dim cMake As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupLists")

For Each cStatus In ws.Range("StatusList")
With Me.cbostatus
.AddItem cStatus.Value
End With
Next cStatus

For Each cMake In ws.Range("MakeList")
With Me.cbomake
.AddItem cMake.Value
End With
Next cMake

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime error 1004 pastespecial method of range class failed dreamz[_29_] Excel Programming 5 February 3rd 06 02:57 PM
runtime error 1004 method range of object global failed dreamz[_26_] Excel Programming 3 January 26th 06 07:23 PM
runtime error 1004 method range of object '_global failed valdesd Excel Discussion (Misc queries) 2 October 6th 05 07:26 PM
Runtime Error 1004 - Method Range of '_Global failed' Sworkhard Excel Programming 3 July 9th 04 04:20 AM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"