jmthompson
Well-known Member
- Joined
- Mar 31, 2008
- Messages
- 966
How could I change this code to find the cell = MyMonthandYear and delete all columns to the left of that column up to and including column "P"? Basically, in the range from P-last column, I want to keep the column with header that matched MyMonthandYear and all columns to the right of that column.
Code:
Sub MyColumn()
MyMonthandYear = Format(Date, "mmmm-yy")
LastColumn = Range("IV1").End(xlToLeft).Column
For i = LastColumn To 16 Step -1
If (Cells(1, i).Value) <> MyMonthandYear Then
Cells(1, i).EntireColumn.Delete
End If
Next i
End Sub