自动填充到列中的最后一行

我试图创build一个macros,编辑单元格C2为0,然后自动填充到列减1(与j的行)的最后一行。 该代码适用于3组logging,但是当有多组数据时,它不会自动填充到最后一行。 例如,如果有4条logging,它只会自动填充到第3行,第4行仍然会有它的旧值。 当logging数量发生变化时,如何填充到最后一行。

数据:

ID | NAME | CODE 1 | JON | 200 2 | ANNA | 300 3 | TIM | 400 jjj | jjjjjj | jjjjj 

码:

 Dim codeCol as Long range("C2").Select ActiveCell.FormulaR1C1 = "0" codeCol = Cells(1, Columns.Count).End(xlToLeft).Column Selection.AutoFill Destination:=range("C2:H" & codeCol - 6), Type:=xlFillDefault 

输出:

 ID | NAME | CODE 1 | JON | 0 2 | ANNA | 0 3 | TIM | 0 jjj | jjjjjj | jjjjj 

经testing

尝试这个

 Sub test() With ActiveSheet ' range("A" & rows.count).end(xlup).row) - tells the position of last used row in A column .Range("C2:C" & .Range("A" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "0" End With End Sub 

根据您的需要更改代码