Select Rows before today & Copy PasteValue Numbers

bcurrey

Board Regular
Joined
Aug 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. MacOS
I have a spreadsheet that summarizes basic inbound/outbound numbers each day. Columns B&C are COUNTIFS off of a SQL table on a separate tab. The SQL code only keeps the most recent 7 days of data stored in the workbook.

I need VBA that will select the row prior to today, Copy & PasteValues so that the numbers don't get lost after 7 days pass.

Any ideas? Thanks!



DateKeyedReceipts# to key
4/25/20183151245930
4/26/2018540356746
4/27/201800746
4/30/201800746
5/1/201800746
5/2/201800746
5/3/201800746
5/4/201800746
5/7/201800746
5/8/201800746
5/9/201800746
5/10/201800746
5/11/201800746
5/14/201800746
5/15/201800746
5/16/201800746

<tbody>
</tbody>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
try this

Code:
  Sub SavePrior()    Dim s1 As Worksheet, s2 As Worksheet
    Dim lr As Long, lr2 As Long, i As Long
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
        If s1.Range("A" & i) < Date Then
            s1.Range("A" & i & ":D" & i).Copy
            s2.Range("A" & lr2 + 1).PasteSpecial xlPasteValues
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "Action Complete"
End Sub
 
Upvote 0
Awesome Alan! It works perfect. I really appreciate it!!


try this

Code:
  Sub SavePrior()    Dim s1 As Worksheet, s2 As Worksheet
    Dim lr As Long, lr2 As Long, i As Long
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
        If s1.Range("A" & i) < Date Then
            s1.Range("A" & i & ":D" & i).Copy
            s2.Range("A" & lr2 + 1).PasteSpecial xlPasteValues
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "Action Complete"
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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