VBA CODE HELP

zmbe_clare

New Member
Joined
Jul 17, 2022
Messages
3
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Need some help with a code that lets me clear contents for a cell that is over a year old, then also clears the contents on the remaining row until a certain point. The first cell in the row will have the date, and the next two cells will have data that needs to be cleared, adn the rest of the contents in the sheet with have to move up so there is not a gap at the top of the sheet.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This is the code that i have so far, and all it does is deletes the cell with the date older then a year.

Sub Date_test()
Dim ddate As Date
Dim rCell As Range
Dim r As Long

With Sheets("DateTest")
For Each rCell In .Range(.Cells(18, "B"), .Cells(31, "B").End(xlUp))
If rCell <= Now() - 365 Then
rCell.ClearContents
End If
Next rCell


End With

End Sub
 
Upvote 0
VBA Code:
.range(.cells(rcell.row,1), .cells(rcell.row,3).clearcontents.
I am not sure how you would end up with a gap at the top?

You could delete the cells and shift cell up if required or just delete the entire row unless there is other stuff next to it you don't want deleted.
 
Upvote 0
VBA Code:
.range(.cells(rcell.row,1), .cells(rcell.row,3).clearcontents.
I am not sure how you would end up with a gap at the top?

You could delete the cells and shift cell up if required or just delete the entire row unless there is other stuff next to it you don't want deleted.
That is actually what I was looking to accomplish, and I'm new to VBA coding; and I'm not sure how to code that action.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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