'问题:不指定l,m参数,如何实现自动往下复制公式?
Sub aaaa()
Dim i As Integer
Dim j As Integer
Dim l As Integer
Dim m As Integer
l = 10
m = 15
i = 4
j = 10
Range("C" & j & "").Select
Cells(10, 3).Formula = "=sum(B" & i & ":" & "B" & j & ")/7"
Selection.AutoFill Destination:=Range("C" & l & " : C" & m & "")
'已在cells(10,3)单元格中得到公式=sum(B4:B10)/7
'现在我想自动复制公式到本列以下的单元格
'(如:cells(11,3)、cells(12,3) ……中得到公式)
End Sub
其实,说白了,是想知道是否还有更为精炼的解决之道?谢谢Roadbeg兄。作者: Roadbeg 时间: 2003-2-22 18:38
精益求精,竹笛兄的精神令人佩服.
这使我想起了以前看到的一个经典例子:
如何不用第三个变量,交换两个变量的值?
解法非常精彩,不知各位高手可有兴趣解一解此题?作者: 竹笛 时间: 2003-2-22 19:06
估计是精炼的解决之道,但还不是我最满意的:
Sub aaaa()
Dim i As Integer '确定行号
Dim l As Integer '确定行记录数
Dim n As Integer 'n天移动平均产量
n = Cells(3, 7) '确定几天的移动平均产量
i = n + 1 '确定第一个要写入公式的单元格
l = Cells(4, 7) '确定行记录数
Range("C" & i & "").Select
Cells(n + 1, 3).Formula = "=sum(B2:" & "B" & i & ")/" & n & ""
Selection.AutoFill Destination:=Range("C" & i & " : C" & l & "")
End Sub
[em26]文件下载作者: huanghai 时间: 2003-2-22 19:22
我这里面有一段代码,我一直在用的:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim row1, con1 As Integer
row1 = Target.Row
con1 = Target.Column
If con1 = 3 And Cells(row1, 3) <> "" Then
Cells(row1, 2) = row1 - 2
End If
If con1 = 5 Or con1 = 6 Then
Cells(row1, 7).Formula = "=SUM($E$3:E" & row1 & ")-SUM($F$3:F" & row1 & ")"
End If