Flexibility not to run macro on a specific day of the week

jjohn98

New Member
Joined
Oct 2, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello.

I would like to create a macro that would take data from "Sheet1" and add it under the existing data in "Sheet2" and roll off 1 weeks' worth of information from "Sheet2" at the same time. At any one time I would like Sheet2 to contain only 13 weeks of data, the current week (imported) and past twelve weeks (remove the old 14th week). The macro I have written is below. I would like the flexibility of not running the macro on a specific day. Can someone help? Thank you.

Sub DeleteRows()

Dim LR As Long, I As Long

Application.ScreenUpdating = False

Application.Calculation = xlCalculationManual

LR = Range("B" & Rows.Count).End(xlUp).Row

For I = LR To 1 Step -1

If Range("B" & I).Value <= Date - 93 Then Rows(I).Delete

Next I

Application.ScreenUpdating = True

Application.Calculation = xlCalculationAutomatic

End Sub
 

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.
I forgot to add the copy part of the macro

Sub CopyInfo()

Sheets("Sheet1").Select

lrow = Cells.Find("*", Cells(2, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row

Range("A2:Q" & lrow).Copy

Sheets("Sheet2").Select

ltarget = Cells.Find("*", Cells(2, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row

Cells(ltarget + 1, 1).Select

ActiveSheet.Paste
End Sub
 
Upvote 0
I would like the flexibility of not running the macro on a specific day.

VBA Code:
Sub TestDay()
    If Weekday(Date) = vbTuesday Then
        MsgBox "Not to day big boy"
        Exit Sub
    End If
End Sub
 
Upvote 0
VBA Code:
Sub TestDay()
    If Weekday(Date) = vbTuesday Then
        MsgBox "Not to day big boy"
        Exit Sub
    End If
End Sub
Thank you for the reply, but not exactly what I was looking for. I would like the code to look at the dates in date column and just keep 13wks of information based on the most recent date in that column
 
Upvote 0
I'm new to VB.... I found this which is close to what I want to do. I'm trying to run a macro that will clear a tab after a specific date. I've come up with this, but it's not working. I suspect it's how I have the hard date. Any suggestions?

Sub ClearData()

If Weekday(Date) >= "01/01/2023" Then
Sheets("RawData").Select
Cells.Select
Selection.ClearContents
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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