Reputation: 1695
I need to delete a range of rows using two named ranges
Current find the column numbers for the last column (lastColumn) and then the column 6 spots behind it (colrange)
Dim lastColumn As Integer
With ActiveSheet
lastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
colrange = lastColumn - 6
I want to delete the columns in the range colrange:lastColumn but not sure how to do this?
Upvotes: 0
Views: 57
Reputation: 7979
you can simply use:
Range(Columns(colRange),Columns(lastColumn)).Delete
or directly:
With ActiveSheet
.Range(.Columns(.Cells(1, .Columns.Count).End(xlToLeft).Column - 6), .Columns(.Cells(1, .Columns.Count).End(xlToLeft).Column)).Delete
End With
Upvotes: 1
Reputation: 27249
Range(Cells(1,colRange),Cells(1,lastColumn)).EntireColumn.Delete
Upvotes: 2