user8375801
user8375801

Reputation:

Deleting all columns between the first one and the last four on a sheet

I have a worksheet here with multiple columns full of data, ranging from cell AA to CT currently. The first column contains rows with headings and is frozen. Data is added to the end column of this range weekly. & Then all columns between the first and the last four are deleted (to show a month's worth of data but keep the headings intact).

I'm very new to VBA and I've been trying to write some code to automate this, so far I've managed to select the 5th column in from the end. But I can't get it to select the columns in between the 4th column from the end and Cell AA:

Sub DeleteColumns()
     Dim i
     i = Range("KFIData").End(xlToRight).Offset(0,-4).EntireColumn.Select
     Columns("AA:ColumnFive").Delete
End Sub

Am I going about this completely the wrong way?

Many thanks

Upvotes: 1

Views: 58

Answers (1)

A.S.H
A.S.H

Reputation: 29352

Well if you managed to catch column 5 from the end, use this statement:

Range(Columns("AA"), Columns(ColumnFiveFromEnd)).Delete

ColumnFiveFromEnd can be a number as well as a text identifier.

Upvotes: 1

Related Questions