|
楼主 |
发表于 2013-9-28 12:23
|
显示全部楼层
Sub M5转下月()
Dim n As Integer
Dim m As Range
Dim wksheet As Worksheet
Dim wksheet2 As Worksheet
ActiveSheet.Unprotect Password:="161602"
MsgBox "将结转到下月,如执行了操作而又不想转到下月,请不要保存,如已保存可重新打开删除表"
For Each wksheet In Worksheets
If wksheet.Name = "12月份" Then 存在 = True
Next wksheet
If 存在 = True Then
aa = MsgBox("已存在12月份表,将要结转下年" & _
Chr(10) & "结转下年将删除1-12月份表!请先做好备份!", 0, "备份提示")
If aa = 1 Then GoTo f10
Else
ActiveSheet.Copy Before:=Sheets(1)
Range("j3").Select
Set m = Range("j3")
mym = Len(m)
Select Case mym
Case Is = 3
n = Left(m, 1)
n = n + 1
Case Is = 4
n = Left(m, 2)
If n = 10 Or n = 11 Then
n = n + 1
Else
MsgBox "请检查表标签是是否正确,请重新选择!"
GoTo f10
End If
Case Else
MsgBox "请检查表标签是是否正确,请重新选择!"
GoTo f10
End Select
End If
'改表名
Range("j3").Select
Range("j3").Value = n & "月份"
For Each wksheet2 In Worksheets
If wksheet2.Name = n & "月份" Then 存在 = True
Next wksheet2
If 存在 = True Then
MsgBox "请检查是否选错了月份,要结转的月份已存在!请重新选择结转"
Application.DisplayAlerts = False
On Error GoTo f10
ActiveSheet.Delete
Application.DisplayAlerts = True
GoTo f10
Else
ActiveSheet.Name = Range("j3").Value
End If
'开始复制累计折旧
k = ActiveSheet.[k65536].End(xlUp).Row
For n = 5 To k
On Error Resume Next
J = Application.WorksheetFunction.Round(Cells(n, 8) * (1 - Range("N3")) / Cells(n, 3) / 12, 2)
Cells(n, 9) = Application.WorksheetFunction.Round(Cells(n, 11), 2)
Cells(n, 13) = Cells(n, 13).Value
If Cells(n, 12) - Cells(n, 7) < J And Cells(n, 12) - Cells(n, 7) < 0 Then
Cells(n, 10) = Cells(n, 8) - Cells(n, 9) - Cells(n, 7)
ElseIf Cells(n, 12) - Cells(n, 7) < 0 And Cells(n, 10) > 0 Then
Cells(n, 10) = Cells(n, 12) - Cells(n, 7) + Cells(n, 10)
ElseIf Cells(n, 12) - Cells(n, 7) < 0 And Cells(n, 10) = 0 Then
Cells(n, 10) = 0
ElseIf Cells(n, 12) - Cells(n, 7) < 0 Then
Cells(n, 10) = Cells(n, 12) - Cells(n, 7) - Cells(n, 10)
ElseIf Cells(n, 12) - Cells(n, 7) = J And Cells(n, 10) < 0 Then
Cells(n, 10) = 0
ElseIf Cells(n, 12) - Cells(n, 7) = 0 And Cells(n, 10) > 0 Then
Cells(n, 10) = 0
End If
Cells(n, 13) = Cells(n, 13) + Cells(n, 10)
If Cells(n, 10).Value > 0 Then Cells(n, 16) = Cells(n, 16) + 1
Next n
GoTo f11
f10:
ActiveWindow.Close
f11:
'除汇总
ActiveSheet.Unprotect Password:="161602"
Cells.Select
Selection.RemoveSubtotal
Range("A5").Select
M3汇总 '调用
ActiveSheet.Protect Password:="161602"
Worksheets(2).Select
ActiveSheet.Protect Password:="161602"
Worksheets(1).Select
End Sub
|
|