Till now every thing was fine, but today when i try to activate the form i got the "message run-time error '1004' method 'range' of object '_worksheet' failed"
when i press on debug it take me to
Sub show()
Form1.show
End Sub
here is all the code, someone can help please?
Private Sub cboDay_Change()
End Sub
Private Sub cboFinish_Change()
End Sub
Private Sub cboLoc_Change()
End Sub
Private Sub cboMoney_Change()
End Sub
Private Sub cboShift_Change()
End Sub
Private Sub cboStart_Change()
End Sub
Private Sub cboTotal_Change()
End Sub
Private Sub cmdAdd_Click()
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("דוח שעות")
'find first empty row in database
lRow = Application.Max(ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row)
'check for a part number
If Trim(Me.txtDate.Value) = "" Then
Me.txtDate.SetFocus
MsgBox "הכנס תאריך"
Exit Sub
End If
If Trim(Me.cboDay.Value) = "" Then
Me.cboDay.SetFocus
MsgBox "הכנס יום"
Exit Sub
End If
If Trim(Me.cboShift.Value) = "" Then
Me.cboShift.SetFocus
MsgBox "הכנס משמרת"
Exit Sub
End If
If Trim(Me.cboStart.Value) = "" Then
Me.cboStart.SetFocus
MsgBox "הכנס שעת התחלה"
Exit Sub
End If
If Trim(Me.cboFinish.Value) = "" Then
Me.cboFinish.SetFocus
MsgBox "הכנס שעת סיום"
Exit Sub
End If
If Trim(Me.cboTotal.Value) = "" Then
Me.cboFinish.SetFocus
MsgBox "הכנס סהכ"
Exit Sub
End If
If Trim(Me.cboMoney.Value) = "" Then
Me.cboMoney.SetFocus
MsgBox "הכנס כסף"
Exit Sub
End If
If Trim(Me.cboLoc.Value) = "" Then
Me.cboLoc.SetFocus
MsgBox "הכנס אתר"
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
.Cells(lRow, 1).Value = Me.txtDate.Value
.Cells(lRow, 2).Value = Me.cboDay.Value
.Cells(lRow, 3).Value = Me.cboShift.Value
.Cells(lRow, 4).Value = Me.cboStart.Value
.Cells(lRow, 5).Value = Me.cboFinish.Value
.Cells(lRow, 6).Value = Me.cboTotal.Value
.Cells(lRow, 7).Value = Me.cboMoney.Value
.Cells(lRow, 8).Value = Me.cboLoc.Value
' .Protect Password:="password"
End With
'clear the data
Me.txtDate.Value = ""
Me.cboDay.Value = ""
Me.cboShift.Value = ""
Me.cboStart.Value = ""
Me.cboFinish.Value = ""
Me.cboMoney.Value = ""
Me.cboTotal.Value = ""
Me.cboLoc.Value = ""
ActiveWorkbook.Save
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub cmdDel_Click()
Dim ctl
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.TextBox Then
ctl.Value = ""
End If
Next ctl
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.ComboBox Then
ctl.Value = ""
End If
Next ctl
End Sub
Private Sub CommandButton2_Click()
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub Label2_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Label4_Click()
End Sub
Private Sub Label5_Click()
End Sub
Private Sub Label6_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub Label8_Click()
End Sub
Private Sub txtDate_Change()
End Sub
Private Sub Label9_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Initialize()
Dim cDay As Range
Dim cShift As Range
Dim cStart As Range
Dim cFinish As Range
Dim cMoney As Range
Dim cTotal As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("Lists")
For Each cDay In ws.Range("יום")
With Me.cboDay
.AddItem cDay.Value
End With
Next cDay
For Each cShift In ws.Range("משמרת")
With Me.cboShift
.AddItem cShift.Value
End With
Next cShift
For Each cStart In ws.Range("התחלה")
With Me.cboStart
.AddItem cStart.Value
End With
Next cStart
For Each cFinish In ws.Range("סיום")
With Me.cboFinish
.AddItem cFinish.Value
End With
Next cFinish
For Each cTotal In ws.Range("סהכ")
With Me.cboTotal
.AddItem cTotal.Value
End With
Next cTotal
For Each cMoney In ws.Range("כסף")
With Me.cboMoney
.AddItem cMoney.Value
End With
Next cMoney
For Each cLoc In ws.Range("אתר")
With Me.cboLoc
.AddItem cLoc.Value
End With
Next cLoc
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the Close Form button!"
End If
End Sub
שעות מ.א.xlsmשעות מ.א.xlsm
Bookmarks