Public rctr
Public cctr
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Call RCount
Call CCount
If Range("B" & rctr) = "" Then
Range("A" & rctr).Select
ActiveCell.FormulaR1C1 = "=COUNTA(R2C:R[-1]C)"
Selection.AutoFill Destination:=Range("A" & rctr & ":" & Cells(rctr, cctr - 1).Address), Type:=xlFillDefault
Range("B" & rctr + 1).Select
ActiveCell.FormulaR1C1 = "=R[-1]C1-R[-1]C"
Selection.AutoFill Destination:=Range("B" & rctr + 1 & ":" & Cells(rctr + 1, cctr - 1).Address), Type:=xlFillDefault
Cells(1, cctr).Select
ActiveCell.FormulaR1C1 = "TOTAL"
Cells(2, cctr).Select
ActiveCell.FormulaR1C1 = "COUNTA(RC2:RC[-1])"
Selection.AutoFill Destination:=Range(Cells(2, cctr).Address & ":" & Cells(rctr - 1, cctr).Address), Type:=xlFillDefault
Range("A1").Select
Else
Beep
End If
End Sub
Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+C
'
Call RCount
Call CCount
If Range("B" & rctr) <> "" Then
Range("A" & rctr - 1 & ":" & Cells(rctr, cctr).Address).Select
Selection.ClearContents
Range(Cells(1, cctr - 1).Address & ":" & Cells(rctr, cctr - 1).Address).Select
Selection.ClearContents
Range("A1").Select
Else
Beep
End If
End Sub
Sub RCount()
rctr = 1
Do
rctr = rctr + 1
Loop While (Range("A" & rctr) <> "")
End Sub
Sub CCount()
cctr = 1
Do
cctr = cctr + 1
**Loop While (Cells("A" & cctr).Address <> "")**
End Sub
我有一个运行时错误 1004 Application defined or object define error with this loop 。有人请帮帮我。我不知道该怎么办。我是 VBA 编程的新手