Help! My Macro is only deleting every other column- how to work from right???

jmthompson

Well-known Member
Joined
Mar 31, 2008
Messages
966
This macro is skipping columns and I know it's because I should work from the last column back, but I don't have the brain power to fix it, help?


Code:
Sub MyMonth()
TheDate = Format(Now, "mmm yy")
LastColumn = Range("IV11").End(xlToLeft).Column
Dim c As Range
        For Each c In Range([P1], Cells("1", Columns.Count).End(xlToLeft))
            If c <> TheDate Then c.EntireColumn.Delete
        Next c

End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Any time you delete rows or columns you need to work backwards (right-to-left; bottom-to-top). Generically
Rich (BB code):
for i = rngSomeRange.Rows/Columns.Count to 1 Step -1
     '// «code that does deletion»<DELETION>
Next i
 
Upvote 0

Forum statistics

Threads
1,216,122
Messages
6,128,958
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top