Delete same column until value is met !!!

MarkReddell

Board Regular
Joined
Sep 1, 2011
Messages
210
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hello Everyone! I need a macro keep deleting until the value is met!!! I have this code, but it stops after the first column is deleted instead of deleting the next new Column H until it = Today. How do I get it to Loop? Please, any help???
Code:
Sub DeleteSpecifcColumn()    
    Set MR = Range("H4")
    For Each cell In MR
        If cell.Value < Date Then cell.EntireColumn.Delete
    Next
End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
explain more about how wide your columns are. Your code dosen't seem to be set to loop

Does H change after you have looped the first time

You seem to be using H4 for MR and then deleting H4
 
Last edited:
Upvote 0
I'm not really sure what the "MR" is! I found this code online! I really need to delete Column H over & over until h4=today()<today()<today(), &="" then="" continue="" to="" delete="" col.="" h="" until="" h4<today()<="" html=""></today()<today(),>
 
Last edited:
Upvote 0
does row 4 always contain data, until the width of the data has been used

how many rows before and after are in use

how do you expect to trigger the code

what is the range of your dates, any integer can be a date going back to the 1900's, 1 is a valid date

would any dates appear that are text only?
 
Upvote 0
I'm trying to program a Branson Show Schedule to auto delete ALL Column where the date has passed! In H4:NF4 is FULL year of dates in each Column. starting with Jan 1 to dec 31. I need to have code to run when I open my file to delete column H over & over until the current date is reach in whatever Column that Might be & then stop on the current date. I can with the code above get it to delete column H, but I need it to continue until the current date is reached!!! I hope that this is clear enough, & I really thank you for your help! Mark@Reddell.Com
 
Upvote 0
Something like this perhaps?

Code:
Sub DeleteOldColumns()
    Do Until Cells(4, 8).Value >= Date Or Cells(4,8).Value = vbNullString
        Columns(8).Delete
    Loop
End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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