|
各位论坛高手,有一代码,以前运行无误,现在运行提示缺少for或next,什么原因?请高手相助。谢谢。
Public Sub 添加部门名称及合计()
For n = Range("b65536").End(xlUp).Row To 3 Step -1
If Cells(n, 2) <> Cells(n + 1, 2) Then
If i <> 0 Then
Cells(i, 8) = Hj
Cells(i, 4) = Hj
Cells(i, 6) = Hj
Cells(i, 7) = Hj
Hj = 0
i = n + 1
If Range("b" & i) <> "" Then
Rows(i & ":" & i + 2).Insert Shift:=xlDown
Range("A1:y1").Copy Range("A" & i + 2)
End If
Cells(i, 2) = Cells(n, 2)
Cells(i, 2) = "合计"
End If
Hj = Hj + Cells(n, 8)
Hj = Hj + Cells(n, 4)
Hj = Hj + Cells(n, 6)
Hj = Hj + Cells(n, 7)
Next
Cells(i, 8) = Hj
Cells(i, 4) = Hj
Cells(i, 6) = Hj
Cells(i, 7) = Hj
End Sub
|
|