move rows into different sheets by date per quarter.

jbott370

New Member
Joined
Oct 31, 2018
Messages
2
So i have a spread sheet and have code adopted from varrious sources to move rows into different sheets based on the date entered into column "A". the sheets are labled by quarter but the code i have moves the row into all sheets instead of the specified one. here is the code i have tried to adapt

Private Sub Worksheet_Change(ByVal Target As Range)


If Intersect(Target, Range("A4:A62")) Is Nothing Then Exit Sub
If Target.Cells.Count < 1 Then Exit Sub
On Error Resume Next
If Target.Value < "04/01/2018" & Target.Value > "12/31/2017" Then
Target.EntireRow.Copy Sheets("CI Q1 2018").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
If Target.Value < "07/01/2018" & Target.Value > "03/31/2018" Then
Target.EntireRow.Copy Sheets("CI Q2 2018").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
If Target.Value < "10/01/2018" & Target.Value > "06/30/2018" Then
Target.EntireRow.Copy Sheets("CI Q3 2018").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
If Target.Value < "12/31/2018" & Target.Value > "09/30/2018" Then
Target.EntireRow.Copy Sheets("CI Q4 2018").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Application.EnableEvents = False
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long


With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet


'We select the sheet so we can change the window view
.Select


'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView


'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False


'Set the first and last row to loop through
Firstrow = 4
Lastrow = 62


'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1


'We check the values in the A column in this example
With .Cells(Lrow, "A")


If Not IsError(.Value) Then


If .Value <> "" Then .EntireRow.Delete
'This will delete each row with the Value "ron"
'in Column A, case sensitive.


End If


End With


Next Lrow


End With


ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With


Application.EnableEvents = True
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You need to compare values of type Date to make it work and also the ampersand character is a concatneation command not and logical and command the so you need to change all your if statements to this foramt

Code:
If Target.Value < CDate("04/01/2018") And Target.Value > CDate("31/12/2017") Then

Note I change the date format of the character strings because I am in England
 
Upvote 0
You need to compare values of type Date to make it work and also the ampersand character is a concatneation command not and logical and command the so you need to change all your if statements to this foramt

Code:
If Target.Value < CDate("04/01/2018") And Target.Value > CDate("31/12/2017") Then

Note I change the date format of the character strings because I am in England
That worked perfectly thank you very much!
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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