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!



[TABLE="width: 360"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Keyed[/TD]
[TD]Receipts[/TD]
[TD]# to key[/TD]
[/TR]
[TR]
[TD]4/25/2018[/TD]
[TD]315[/TD]
[TD]1245[/TD]
[TD]930[/TD]
[/TR]
[TR]
[TD]4/26/2018[/TD]
[TD]540[/TD]
[TD]356[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]4/27/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]4/30/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/1/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/2/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/3/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/4/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/7/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/8/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/9/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/10/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/11/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/14/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/15/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
[TR]
[TD]5/16/2018[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]746[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,224,833
Messages
6,181,237
Members
453,026
Latest member
cknader

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