|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面这段代码是编制“提示到龄退休员工”
运行显示“运行时错误“9” 下标越界”
点击调试,“arrRmContent(1, k) = arrData(i, 1)” 上面语句变成黄色。
请问如何处理。
我学的这段编程excel中录入的“员工信息”条目为10条,如果“员工信息”条目为20条,请问编程该如何修改。谢谢,请高手们指点。
全部编程如下:
Dim iRemindTimes As Integer
Const AllowRtTimes = 100
Const BefDays = 60
Private Function RetireDay(ByVal datBirthDay As Date, ByVal strSex As String, ByVal strCap As String) As Date
Dim iRtage As Integer
iRtage = IIf(strSex = "男", 60, IIf(strCap = "工人", 50, 55))
RetireDay = DateSerial(Year(datBirthDay) + iRtaAge, Month(datBirthDay), Day(datBirthDay))
End Function
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim arrData
Dim i As Integer
Dim k As Integer
Dim datRtr As Date
Dim arrRmContent
if iRemindTimes >= AllowRtTimes Then Exit Sub
If Sh.Name = "人事数据表" Then
iRemindTimes = iRemindTimes + 1
arrData = Range("b3:k3" & [b65536].End(xlUp).Row)
ReDim arrRmContent(1 To 11, 1 To UBound(arrData))
arrRmContent(1, 1) = "工号"
arrRmContent(2, 1) = "姓名"
arrRmContent(3, 1) = "部门"
arrRmContent(4, 1) = "学历"
arrRmContent(5, 1) = "生日"
arrRmContent(6, 1) = "性别"
arrRmContent(7, 1) = "入职"
arrRmContent(8, 1) = "职称"
arrRmContent(9, 1) = "职务"
arrRmContent(10, 1) = "身份"
arrRmContent(11, 1) = "退休日期"
k = 1
For i = 1 To UBound(arrData)
datRtr = RetireDay(arrData(i, 5), arrData(i, 6), arrData(i, 10))
If RetireDay(arrData(i, 5), arrData(i, 6), arrData(i, 10)) - Now < BefDays Then
k = k + 1
arrRmContent(1, k) = arrData(i, 1)
arrRmContent(2, k) = arrData(i, 2)
arrRmContent(3, k) = arrData(i, 3)
arrRmContent(4, k) = arrData(i, 4)
arrRmContent(5, k) = arrData(i, 5)
arrRmContent(6, k) = arrData(i, 6)
arrRmContent(7, k) = arrData(i, 7)
arrRmContent(8, k) = arrData(i, 8)
arrRmContent(9, k) = arrData(i, 9)
arrRmContent(10, k) = arrData(i, 10)
arrRmContent(11, k) = datRtr
End If
Next i
ReDim Preserve arrRmContent(i To 11, 1 To k)
If k > 1 Then
UsfRtRmnd.lstRtRmnd.List = Application.Transpose(arrRmContent)
UsfRtRmnd.Show False
End If
End If
End Sub
Private Sub Workbook_Activate()
If ActiveSheet.Name = "人事数据表" Then Call Workbook_SheetActivate(ActiveSheet)
End Sub
|
|