jocker_boy
Board Regular
- Joined
- Feb 5, 2015
- Messages
- 83
Hello,
I found this code that copy last column and paste n times according to cell value.
How can i adapt to copy the last two columns and also past the same way?
And instead of reference the sheet name, is it possible to change to active sheet?
Thanks,
Gonçalo
I found this code that copy last column and paste n times according to cell value.
How can i adapt to copy the last two columns and also past the same way?
And instead of reference the sheet name, is it possible to change to active sheet?
Thanks,
Gonçalo
VBA Code:
Sub YearsNumberReduction()
Dim LastCol As Long
Dim DelCnt As Integer
DelCnt = Sheets("Panel").Range("E19").Value
Dim copyCol As Range
Dim DestRange As Range
Dim lastRow As Long
With ThisWorkbook.Sheets("Current")
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
Set copyCol = .Range(.Cells(1, LastCol), .Cells(lastRow, LastCol))
Set DestRange = .Range(.Cells(1, LastCol), .Cells(lastRow, LastCol + DelCnt))
copyCol.AutoFill Destination:= DestRange, Type:=xlFillDefault
End With