PDA

View Full Version : Find seven columns that come before last column.



cccontract
06-23-2015, 06:43 PM
I am trying to find the seven columns that come before the last column.
I find the last column using: (ws.Range("A65536").End(xltoright).Column).
I would like to then take this range of the seven last columns and paste it into another workbook.
I have tried using offset but I'm pretty new and can't seem to get it to work.

Paul_Hossler
06-24-2015, 10:16 AM
You were on the right track. Here's two version, since it wasn't clear if you want the last column+6, or seven before but not inclusing last col




Option Explicit
Sub drv()
MsgBox Last7.Address
MsgBox Last7Before.Address
End Sub

Function Last7() As Range
With ActiveSheet
Set Last7 = .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, -6).Resize(1, 7).EntireColumn
End With
End Function

Function Last7Before() As Range
With ActiveSheet
Set Last7Before = .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, -7).Resize(1, 7).EntireColumn
End With
End Function