Thread: Auto move a row
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Doug M... Doug M... is offline
external usenet poster
 
Posts: 2
Default Auto move a row

Thank You Jim...
Please excuse my low level of understanding i am just trying to help a
secretary. Question is where do i need to insert this code you have
generously shared? Thanks Doug
--
Thanks Doug


"Jim Thomlinson" wrote:

Before someone else pick it out I missed one line in my previously posted
solution...
Here is the new sub...

Private Const intDateColumn As Integer = 2

Public Sub MovePastRecords()
Dim wksCurrent As Worksheet
Dim wksPast As Worksheet
Dim rngCurrent As Range
Dim rngPast As Range
Dim blnCopyRow As Boolean

Set wksCurrent = Sheets("Current")
Set wksPast = Sheets("Past")
Set rngCurrent = wksCurrent.Range("A65535").End(xlUp)
Set rngPast = wksPast.Range("A65535").End(xlUp).Offset(1, 0)

Do While rngCurrent.Row 1
If rngCurrent.Offset(0, intDateColumn - 1).Value < Date Then
blnCopyRow = True
Set rngCurrent = rngCurrent.Offset(-1, 0)
If blnCopyRow = True Then
rngCurrent.Offset(1, 0).EntireRow.Copy rngPast
rngCurrent.Offset(1, 0).EntireRow.Delete
Set rngPast = rngPast.Offset(1, 0)
End If
blnCopyRow = False '***New line originally missed
Loop

End Sub

"Excel Challenged" wrote:

We have an events spread sheet listing facility usage by date. Showing room
number, time, who, event, and such. Is it possible to have the expired
rows€¦€¯any date past the computers present date€¯ automatically moved to
another sheet rather than manually deleting past events? Thanks for your
help to this new excel user. Doug