salh90
12-01-2016, 01:05 PM
Hello All!
I am trying to write code to copy then delete rows containing dates (m/d/yyyy format) greater than 30 days old to a new Spreadsheet "Sheet2"
I already have written code to move then delete a specific account type to Sheet 2 using:
If mSession.Screen.GetString(3, 52, 12) = "SECURED CARD" Then
rng.Offset(0, 1).Value = "Yes"
Else: rng.Offset(0, 1).Value = "No"
End If
Dim c As Range
Dim J As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
J = 2 ' Start copying to row 1 in target sheet
For Each c In Source.Range("D2:D100") ' Do 1000 rows
If c = "Yes" Then
Source.Rows(c.Row).Copy Target.Rows(J)
J = J + 1
End If
Next c
'DeletetheSecureds
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 Sheets("Sheet1")
'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 = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'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, "D")
If Not IsError(.Value) Then
If .Value = "Yes" 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
I am trying to write code to copy then delete rows containing dates (m/d/yyyy format) greater than 30 days old to a new Spreadsheet "Sheet2"
I already have written code to move then delete a specific account type to Sheet 2 using:
If mSession.Screen.GetString(3, 52, 12) = "SECURED CARD" Then
rng.Offset(0, 1).Value = "Yes"
Else: rng.Offset(0, 1).Value = "No"
End If
Dim c As Range
Dim J As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
J = 2 ' Start copying to row 1 in target sheet
For Each c In Source.Range("D2:D100") ' Do 1000 rows
If c = "Yes" Then
Source.Rows(c.Row).Copy Target.Rows(J)
J = J + 1
End If
Next c
'DeletetheSecureds
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 Sheets("Sheet1")
'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 = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'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, "D")
If Not IsError(.Value) Then
If .Value = "Yes" 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