|
本帖最后由 zhangzhezy 于 2023-7-5 18:05 编辑
Sub 工资表_存档()
'工资表数据存档操作
Dim i%, j%, k%, x%
Dim A As Worksheet
Dim B As Worksheet
Set A = Sheets("工资表")
Set B = Sheets("费用数据")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
x = MsgBox("确定数据正确后,更新数据!", vbOKCancel, "提示")
If x = vbOK Then
'用户按下“确认”,执行后续代码
With B
i = .Cells(Rows.Count, "H").End(xlUp).Row + 1
For j = 2 To i - 1
If A.Range("B2") = .Cells(j, "H") Then
i = j
Exit For
End If
Next
For j = 2 To i - 1
If A.Range("B2") = .Cells(j, "H") And A.Range("B2") = .Cells(j, "H") Then
i = j
Exit For
End If
Next
End With
With A
B.Cells(i, 9) = .Range("B5"):
B.Cells(i, 10) = .Range("B6"):
B.Cells(i, 11) = .Range("B7"):
B.Cells(i, 12) = .Range("B8"):
B.Cells(i, 13) = .Range("B9"):
B.Cells(i, 14) = .Range("B10"):
B.Cells(i, 15) = .Range("B11"):
B.Cells(i, 16) = .Range("B12"):
B.Cells(i, 17) = .Range("B13"):
B.Cells(i, 18) = .Range("B14"):
B.Cells(i, 19) = .Range("B15"):
B.Cells(i, 20) = .Range("B16"):
B.Cells(i, 21) = .Range("B17"):
B.Cells(i, 22) = .Range("B18"):
B.Cells(i, 23) = .Range("B19"):
B.Cells(i, 24) = .Range("B20"):
B.Cells(i, 25) = .Range("B21"):
B.Cells(i, 26) = .Range("B22"):
B.Cells(i, 27) = .Range("B23"):
B.Cells(i, 28) = .Range("B24"):
B.Cells(i, 29) = .Range("B25"):
B.Cells(i, 30) = .Range("B26"):
B.Cells(i, 31) = .Range("B27"):
B.Cells(i, 32) = .Range("B28"):
B.Cells(i, 33) = .Range("B29"):
B.Cells(i, 34) = .Range("B30"):
B.Cells(i, 35) = .Range("B31"):
B.Cells(i, 36) = .Range("B32"):
B.Cells(i, 37) = .Range("B33"):
B.Cells(i, 38) = .Range("B34"):
B.Cells(i, 39) = .Range("B35"):
B.Cells(i, 40) = .Range("B36"):
B.Cells(i, 41) = .Range("B37"):
B.Cells(i, 42) = .Range("B38"):
B.Cells(i, 43) = .Range("B39"):
B.Cells(i, 44) = .Range("B40"):
B.Cells(i, 45) = .Range("B41"):
B.Cells(i, 46) = .Range("B42"):
B.Cells(i, 47) = .Range("B43"):
B.Cells(i, 48) = .Range("B44"):
B.Cells(i, 49) = .Range("B45"):
B.Cells(i, 50) = .Range("B46"):
B.Cells(i, 51) = .Range("B47"):
B.Cells(i, 52) = .Range("B48"):
B.Cells(i, 53) = .Range("B49"):
B.Cells(i, 54) = .Range("B50"):
B.Cells(i, 55) = .Range("B51"):
B.Cells(i, 56) = .Range("B52"):
B.Cells(i, 57) = .Range("B53"):
B.Cells(i, 58) = .Range("B54"):
B.Cells(i, 59) = .Range("B55"):
End With
'Call Report
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ActiveWorkbook.SAVE
'MsgBox "数据已更新"
ElseIf x = vbCancel Then
'用户按下“取消”,退出程序
End If
End Sub
其中
- With A
- B.Cells(i, 9) = .Range("B5"):
- B.Cells(i, 10) = .Range("B6"):
- B.Cells(i, 11) = .Range("B7"):
- B.Cells(i, 12) = .Range("B8"):
- B.Cells(i, 13) = .Range("B9"):
- B.Cells(i, 14) = .Range("B10"):
- B.Cells(i, 15) = .Range("B11"):
- B.Cells(i, 16) = .Range("B12"):
- B.Cells(i, 17) = .Range("B13"):
- B.Cells(i, 18) = .Range("B14"):
- B.Cells(i, 19) = .Range("B15"):
- B.Cells(i, 20) = .Range("B16"):
- B.Cells(i, 21) = .Range("B17"):
- B.Cells(i, 22) = .Range("B18"):
- B.Cells(i, 23) = .Range("B19"):
- B.Cells(i, 24) = .Range("B20"):
- B.Cells(i, 25) = .Range("B21"):
- B.Cells(i, 26) = .Range("B22"):
- B.Cells(i, 27) = .Range("B23"):
- B.Cells(i, 28) = .Range("B24"):
- B.Cells(i, 29) = .Range("B25"):
- B.Cells(i, 30) = .Range("B26"):
- B.Cells(i, 31) = .Range("B27"):
- B.Cells(i, 32) = .Range("B28"):
- B.Cells(i, 33) = .Range("B29"):
- B.Cells(i, 34) = .Range("B30"):
- B.Cells(i, 35) = .Range("B31"):
- B.Cells(i, 36) = .Range("B32"):
- B.Cells(i, 37) = .Range("B33"):
- B.Cells(i, 38) = .Range("B34"):
- B.Cells(i, 39) = .Range("B35"):
- B.Cells(i, 40) = .Range("B36"):
- B.Cells(i, 41) = .Range("B37"):
- B.Cells(i, 42) = .Range("B38"):
- B.Cells(i, 43) = .Range("B39"):
- B.Cells(i, 44) = .Range("B40"):
- B.Cells(i, 45) = .Range("B41"):
- B.Cells(i, 46) = .Range("B42"):
- B.Cells(i, 47) = .Range("B43"):
- B.Cells(i, 48) = .Range("B44"):
- B.Cells(i, 49) = .Range("B45"):
- B.Cells(i, 50) = .Range("B46"):
- B.Cells(i, 51) = .Range("B47"):
- B.Cells(i, 52) = .Range("B48"):
- B.Cells(i, 53) = .Range("B49"):
- B.Cells(i, 54) = .Range("B50"):
- B.Cells(i, 55) = .Range("B51"):
- B.Cells(i, 56) = .Range("B52"):
- B.Cells(i, 57) = .Range("B53"):
- B.Cells(i, 58) = .Range("B54"):
- B.Cells(i, 59) = .Range("B55"):
- End With
复制代码 怎么简写,由于要计算的单元格太多,VBA提示过程太大!谢谢大神赐教!
|
|