2017-10-19 101 views
1

我想自动填充我的公式到最后一列。这里是我的代码:自动填充列直到使用宏的最后一列

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

我已经成功地通过可变LastColumn计数的最后一列,但自动填充过程中,它失败了。所以我想从列B开始自动填充列Lastcolumn

请帮忙。我的代码有什么问题?

+0

thanks !!有用!! –

回答

2

你有一个号码LastColumn,所以你不能直接在Range中使用它。用这个代替:

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