我有一个表(Sheet1),在C列中有分数。当我单击按钮时,我希望在单元格B2中的另一个工作表(摘要)中显示总和。单击按钮后,我希望删除表,但总和将保留在单元格B2中。然后,我将继续进入另一个月并进行循环。
到目前为止我的代码:
Private Sub CommandButton1_Click()
Set myRange = Range(ActiveCell, ActiveCell.End(xlUp))
Dim myCount As Integer
myCount = Application.Count(myRange)
Sheets("Summary").Range("B2").Value = "=SUM(C2:C6" & myCount & ")" '
End Sub
答案 0 :(得分:1)
此代码将对Sheet1中列c的摘要表进行总结。确保列B的摘要表上有一个标题。
Private Sub CommandButton1_Click()
Dim sum As Worksheet, ws As Worksheet
Set sum = Sheets("Summary"): Set ws = Sheets("Sheet1")
sum.Range("B" & sum.Range("B1000000").End(xlUp).Offset(1, 0).Row) = WorksheetFunction.sum(ws.Range("C2:C" & ws.Range("C100000").End(xlUp).Row))
ws.Range("A2:C" & ws.Range("A1").SpecialCells(xlCellTypeLastCell).row).ClearContents
End Sub