'VBA AutoFill adjacent dynamic column results in error?
I am trying to AutoFill dynamic and adjacent column but I'm getting an error. Tried lots of tips but nothing works. Would appreciate the help
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)
Solution 1:[1]
Adjacent vs Last Column
Your AutoFill isn't doing anything so I've used just Copy.
Adjacent
Adjacent to the right ALWAYS means the next right column which would be column X in this case.
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
After Last
After last column ONLY means column X, IF W is last column.
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | VBasic2008 |
