我正在尝试自动填充动态和相邻列,但出现错误。尝试了很多技巧,但无济于事。非常感谢您的帮助
Dim Column As Integer
Column = Workbooks("Outbound Month").Worksheets("Summary").Range("A1", Range("A1").End(xlToRight)).Columns.Count + 1
Workbooks("Outbound Month").Worksheets("Summary").Activate
ActiveSheet.Range("W1:W39").AutoFill Destination:=Range(Range(Cells(1, Column), Cells(39, Column)), Type:=xlFillDefault)
答案 0 :(得分:0)
您的AutoFill
没有做任何事情,因此我只使用了Copy
。
与右边的 ALWAYS 相邻,是指右下一个列,在这种情况下为X
列。
Sub AdjacentToTheRightColumn()
Const cWBName As String = "Outbound Month"
Const cWsName As String = "Summary"
Const cRange As String = "W1:W39"
With Workbooks(cWBName).Worksheets(cWsName)
.Range(cRange).Copy .Range(cRange).Offset(0, 1)
End With
End Sub
最后一列之后的仅表示列X
, IF W
是最后一列。
Sub AfterLastColumn()
Const cWBName As String = "Outbound Month"
Const cWsName As String = "Summary"
Const cRange As String = "W1:W39"
Dim LastColumn As Integer
With Workbooks(cWBName).Worksheets(cWsName)
LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Range(cRange).Copy .Range(cRange) _
.Offset(0, LastColumn - Range(cRange).Column + 1)
End With
End Sub