user3682157
user3682157

Reputation: 1695

Delete a range of columns using two named ranges

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

Answers (2)

Dirk Reichel
Dirk Reichel

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

Scott Holtzman
Scott Holtzman

Reputation: 27249

Range(Cells(1,colRange),Cells(1,lastColumn)).EntireColumn.Delete

Upvotes: 2

Related Questions