Move Date Value to another cell if the date is past due.

SantanaKRE8s

Board Regular
Joined
Jul 11, 2023
Messages
131
Office Version
  1. 365
Platform
  1. Windows
I have a VBA that moves entire row to another sheet if the value in a cell is equal to " Resolved". I want to do something similar but with past due dates, but just move the date from cell in "Column T" to cell in "Column S"
If the dates in "Column T" are from today or before move that date to "Column S"


1691692782119.png
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
The only way I would know how to do this is to loop over the rows in T. If the date value meets the requirement, make the adjacent cell in column S ( Offset(0,-1) )= the value in T of that row, then clear T on that row. That assumes both columns are formatted the same.
 
Upvote 0
Something like this? Change column references from A and B to be whatever you need. You may find that either you don't need to disable/enable events or that it doesn't prevent certain events from running anyway. In the latter case, you could use a Public variable in a standard module.
VBA Code:
Sub MoveDates()
Dim Lrow As Long, i As Long
Dim rng As Range

On Error GoTo errHandler
Application.EnableEvents = False
Lrow = Cells.Find(what:="*", After:=Range("A1"), Lookat:=xlPart, LookIn:=xlFormulas, _
               searchorder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
For i = 1 To Lrow
     Set rng = Range("B" & i)
     If rng <= Date Then
          rng.Offset(0, -1) = rng
          rng.Clear
     End If
Next

exitHere:
Set rng = Nothing
Application.EnableEvents = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere

End Sub
 
Upvote 0
Solution
Thnk you, question, can I change the range from "A1" and "B" to "A:A" and "B:B", so that it aplies this function to entire column?
 
Upvote 0
Not sure I understand your question entirely.
A is the column that best defines the range of rows that have data you need to work with. If that is G, change it to G (or whatever). The principle is that if your Need column only had one date in the first row, you obviously would not use that column.
The number (1) defines the row to start at. If you have headers, change that to the first row with data.
B was my "New Dock" column. As I mentioned, change that to T.
 
Upvote 0
I added this in a module but Do I have to somehow identify what sheet is for, Its for my "BACKLOG". In my "BACKLOG" Sheet I already have two other blocks.
 
Upvote 0
Depends. I had it in the sheet module and just ran it against that sheet.
How do you want to trigger the code? Button? Macro list that you get from the Ribbon? Sheet or workbook event? I assumed you would know what to do because you said
I have a VBA that moves entire row to another sheet
So yes, if you run it from a standard module you need a sheet reference. Maybe like
Lrow = Sheets("BACKLOG").Cells.Find(what:="*", ...
and
Set rng = Sheets("BACKLOG").Range("B" & i)

However, I don't see the need for putting the code in a standard module unless you intend to use it on several sheets. In that case, you could not hard code the sheet reference. I think I'd put the code in the sheet module instead.
 
Upvote 0
I added the code directly to the sheet but I have an additional two blocks there so I added as block 3 but it gave a compile error so Im missing something where it starts.

1691768640980.png
 
Upvote 0
Message is pretty clear. You can't just stick Sub ... and/or End Sub in the middle of Sub ... End Sub
Sub defines the beginning, End Sub defines the end.

Pictures of code are of little use to anyone who might answer your posts about code. If you remain stuck, post the code BUT do so within code tags ( click VBA button on posting toolbar).
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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