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
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