EXCEL 用VBA编写自动填充公式功能

Private Sub Worksheet_Activate()
Dim i, n, x As Integer
x = [c1048576].End(xlUp).Row
For i = x To 2 Step -1
For n = x To 2 Step -1
If Cells(n, 2) = Cells(i, 3) Then
Cells(n, 9) = "0"
Exit For
End If
Next
Next
End Sub
我想在这个编码里加入这个功能:第1列输入到什么地方,第8至11列自动填充公式到相应的行数

y=range("A65536").end(xlup).row
for m=2 to y
cells(m,8).FormulaR1C1=你的公式
cells(m,9).FormulaR1C1=
cells(m,10).FormulaR1C1=
cells(m,11).FormulaR1C1=
next
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-05
看了下你的公式运行方式,就是对比是否在C列里有B列的相同数据,有就在第9列写个"0"。写得也怪怪的。帮你改下这样
Private Sub Worksheet_Activate()
For n = 2 To [b65535].End(xlUp).Row
Cells(n, 2).Select
Cells(n, 9) = Evaluate("=IF(COUNTIF(C:C,INDEX(B:B,ROW()))>0,0,"""")")
Cells(n, 8) = Evaluate("你的excel公式")
Cells(n, 10) = Evaluate("你的excel公式")
Cells(n, 11) = Evaluate("你的excel公式")
NextEnd Sub追问

呃,可以留一下你的Q吗?我想详细跟你请教一下

追答

24278528

本回答被提问者采纳
第2个回答  2012-05-05
Private Sub Worksheet_Activate()
Dim i, n, x As Integer
x = [c1048576].End(xlUp).Row
For i = x To 2 Step -1
If Cells(i, 2) = Cells(i, 3) Then
Cells(i, 9) = "0"
Exit For
End If
if cells(i,1)<>"" then
range(cells(i,8),cells(i,11)=i
end if
Next
Next
End Sub
第3个回答  2012-05-05
cells(1,8).resize([a65536].end(3).row,4).filldown
这样?不过你好像第9列另有安排哎