|
楼主 |
发表于 2009-1-5 12:02
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
请楼上的,帮我看下,程序到底错在哪里,运行你的程序可以了?但用在我的程序里还是不行?
程序如下:
Sub 计算工资Aa()
On Error Resume Next
Dim wk As String, ac As String
Dim la As Long
Application.EnableEvents = False
Application.ScreenUpdating = False
wk = "2009考勤表.xls"
If ActiveWorkbook.Name <> "2009工资报表.xls" Then Exit Sub
aa = ActiveSheet.Name '取当前工作表名
ab = RightB(aa, 4) '工资 补贴
ac = Left(aa, Application.WorksheetFunction.Find("份", aa)) '取几月份
'清除原始记录
Row = ActiveSheet.UsedRange.Rows.Count
If Row > 2 Then Rows("3:" & Row).Delete
Dim wb As Workbook
Dim myFileName As String, myPath As String
myPath = ThisWorkbook.Path & "\"
myFileName = wk
If myFileName <> ThisWorkbook.Name Then
Set wb = GetObject(myPath & myFileName)
With wb.Sheets(ac)
row2 = .Range("a65536").End(xlUp).Row '求2009考勤表中"ac"月份最后一行
'从考勤表中复制数据
la = 3
For lw = 5 To row2
Cells(la, 3) = Workbooks(wk).Sheets(ac).Cells(lw, 3)
Cells(la, 4) = Workbooks(wk).Sheets(ac).Cells(lw, 35)
Range("A" & la) = "=row()-2" '行号
Range("E" & la) = "=INDEX(定额单价!D:D,MATCH(C" & la & ",定额单价!C:C,0))" '引入单价公式
Range("H" & la) = "=INDEX(定额单价!G:G,MATCH(C" & la & ",定额单价!C:C,0))" '引入带班长公式
lb = Application.WorksheetFunction.CountIf(Workbooks(wk).Sheets(ac).Range("D" & lw & ":AH" & lw), "工伤")
If lb > 0 Then Range("J" & la) = "工伤" & lb & "天,按20元/天"
Range("K" & la) = lb
Range("I" & la) = "=ROUND((E" & la & "*D" & la & "+G" & la & "-F" & la & "+H" & la & "+K" & la & "*20),)"
la = la + 1
Next
End With
wb.Close False
End If
row1 = Range("C65536").End(xlUp).Row '求最后一行号
row1 = Range("C65536").End(xlUp).Row '求最后一行号
'单元格合并
Range("A" & row1 + 1 & ":D" & row1 + 1).Merge
Range("E" & row1 + 1 & ":H" & row1 + 1).Merge
Range("A" & row1 + 1) = "合 计:"
Range("E" & row1 + 1) = "=DaXie(" & "I" & row1 + 1 & ")"
Range("I" & row1 + 1) = "=sum(I3:I" & row1 & ")"
'本示例将第一行移到窗口的最上面?
Workbooks("2009工资报表.xls").Sheets(aa).Activate
ActiveWindow.ScrollRow = 1
wx:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
[ 本帖最后由 wuxingch 于 2009-1-5 12:04 编辑 ] |
|