我想在工作簿中的所有工作表上重复此代码。
有时可能有1-2个工作表,有时50 +。
Sub HoursTotal()
'
' HoursTotal Macro
'
Range("F2").Select
ActiveCell.FormulaR1C1 = "=SUM(C[-1])"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Total Hours"
Range("G1").Select
End Sub
答案 0 :(得分:5)
这应该这样做。
git submodule foreach git pull
答案 1 :(得分:1)
简单修改当前代码应该这样做:
Sub HoursTotal()
'
' HoursTotal Macro
'
Dim ws as Worksheet
For Each ws in Worksheets
ws.Range("F2").Select
ActiveCell.FormulaR1C1 = "=SUM(C[-1])"
ws.Range("F1").Select
ActiveCell.FormulaR1C1 = "Total Hours"
ws.Range("G1").Select
Next ws
End Sub
但是,如果没有Select
Sub HoursTotal()
'
' HoursTotal Macro
'
Dim ws as Worksheet
For Each ws in Worksheets
ws.Range("F2").FormulaR1C1 = "=SUM(C[-1])"
ws.Range("F1").FormulaR1C1 = "Total Hours"
ws.Range("G1").Select
Next ws
End Sub
答案 2 :(得分:1)
您需要激活工作表,以便excel可以对其进行更改。
`Sub HoursTotal() 作为工作表昏暗
For Each ws In Worksheets
ws.Activate
ws.Range("F2").FormulaR1C1 = "=SUM(C[-1])"
ws.Range("F1").FormulaR1C1 = "Total Hours"
ws.Range("G1").Select 'I don't think you need this line but I included it anyways
Next
结束字幕”