[英]Autofill to the last row in a column
我試圖創建一個宏,將單元格C2編輯為0,然后自動填充到該列減去1的最后一行(帶有j的行)。 該代碼可用於3組記錄,但是當有更多數據集時,它不會自動填充到最后一行。 例如,如果有4條記錄,它將僅自動填充到第三行,而第四行仍具有其舊值。 我如何做到這一點,以便在記錄數更改時填充到最后一行。
數據:
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
經測試
嘗試這個
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
根據需要更改代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.