簡體   English   中英

使用宏自動填充列直到最后一列

[英]Autofill column until last column using macro

我想將公式自動填充到最后一列。 這是我的代碼:

Dim LastColumn As Long
LastColumn = Cells(5, Columns.Count).End(xlToLeft).Column
Selection.AutoFill Destination:=Range("B1:" & LastColumn & "1"), Type:=xlFillDefault

我已經成功地通過變量LastColumn計數了最后一列,但是在自動填充過程中,它失敗了。 所以我想從B列開始自動填充到Lastcolumn列。

請幫忙。 我的代碼有什么問題?

您在LastColumn有一個數字,因此不能直接在Range使用它。 使用此代替:

Selection.AutoFill Destination:=Range(Cells(1, 2), Cells(1, LastColumn)), Type:=xlFillDefault

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM