jmthompson
Well-known Member
- Joined
- Mar 31, 2008
- Messages
- 966
Good morning,
I have created the Macro below to delete all columns from P-last column whose header is not Month-Year (this month should be June-08). I've tested this code with columns whose header is text and with columns whose header is entered as a date and formatted date Month-yy and a combination of the two, either way it deletes all columns from P to the last column. I've tried stepping through the code, and when I hover over MyMonth in the If statement, January appears. When I hover over MyYear, 2005 appears.
Any ideas?
I have created the Macro below to delete all columns from P-last column whose header is not Month-Year (this month should be June-08). I've tested this code with columns whose header is text and with columns whose header is entered as a date and formatted date Month-yy and a combination of the two, either way it deletes all columns from P to the last column. I've tried stepping through the code, and when I hover over MyMonth in the If statement, January appears. When I hover over MyYear, 2005 appears.
Any ideas?
Code:
Sub MyColumn()
MyMonth = Format(Month(Now), "mmmm")
MyYear = Format(Year(Now), "yy")
LastColumn = Range("IV1").End(xlToLeft).Column
For i = LastColumn To 16 Step -1
If (Cells(1, i).Value) <> MyMonth & "-" & MyYear Then
Cells(1, i).EntireColumn.Delete
End If
Next i
End Sub