我正在做这个员工休假数据库,我总是得到这个:
运行时错误9:下标超出范围。
这就是我的代码的样子。并且错误发生在指定的部分。
Private Sub cmdAdd_Click()
Dim RowCount As Long
Dim VLAbsenceUTwPay, VLAbsenceUTwoutPay, VLBalance As Single
Dim SLAbsenceUTwPay, SLAbsenceUTwoutPay, SLBalance As Single
If Me.Reg1.Value = "" Then
MsgBox "Please enter the entry no.", vbExclamation, "Employee Data"
Me.Reg1.SetFocus
End If
'-----VACATION LEAVE------
VLAbsenceUTwPay = Reg9.Value * 0.00208333333
VLAbsenceUTwoutPay = Reg10.Value * 0.00208333333
VLBalance = (Reg11.Value + Reg8.Value) - (VLAbsenceUTwPay + VLAbsenceUTwoutPay)
'-----SICK LEAVE------------
SLAbsenceUTwPay = Reg12.Value * 0.00208333333
SLAbsenceUTwoutPay = Reg13.Value * 0.00208333333
SLBalance = (Reg14.Value + Reg8.Value) - (SLAbsenceUTwPay + SLAbsenceUTwoutPay)
RowCount = Worksheets("Sheet1").Range("B8").CurrentRegion.Rows.Count ' <<< Error line
With Worksheets("Sheet1").Range("B8")
.Offset(RowCount, 0) = Me.Reg1.Value
.Offset(RowCount, 1) = Me.Reg2.Value
.Offset(RowCount, 2) = Me.Reg3.Value
.Offset(RowCount, 3) = Me.Reg4.Value
.Offset(RowCount, 4) = Me.Reg5.Value
.Offset(RowCount, 5) = Me.Reg6.Value
.Offset(RowCount, 6) = Me.Reg7.Value
.Offset(RowCount, 7) = Me.Reg8.Value
.Offset(RowCount, 8) = Me.Reg9.Value
.Offset(RowCount, 9) = VLAbsenceUTwPay
.Offset(RowCount, 10) = Me.Reg10.Value
.Offset(RowCount, 11) = VLAbsenceUTwoutPay
.Offset(RowCount, 12) = Me.Reg11.Value
.Offset(RowCount, 13) = VLBalance
.Offset(RowCount, 14) = Me.Reg12.Value
.Offset(RowCount, 15) = SLAbsenceUTwPay
.Offset(RowCount, 16) = Me.Reg13.Value
.Offset(RowCount, 17) = SLAbsenceUTwoutPay
.Offset(RowCount, 18) = Me.Reg14.Value
.Offset(RowCount, 19) = SLBalance
.Offset(RowCount, 20) = Me.Reg15.Value
End With
End Sub