VBA script req'd to copy range from a column headed '=TODAY()-1' in Excel

PerseveringHarold

New Member
Joined
May 23, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I have a dataset that updates daily. I need to compare each day's new data range with the equivalent range from the day before.

So my Excel sheet has a column headed '=TODAY()' for the new data, and a column headed '=TODAY()-1' for the previous day's data.

I need my VBA script to find the column headed '=TODAY()-1' and copy the range below it into a column in a separate sheet.

I've hunted around for similar threads, but generally they tend to refer to a fixed date, rather than a dynamic date header like '=TODAY()-1'.

Does what I'm looking for seem possible? Thanks.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Run from the sheet where the table and formulas are.
VBA Code:
Sub FindMyFormula()
Application.ScreenUpdating = 0
Dim m As Range
    With ActiveSheet
        Set m = .UsedRange.Cells.Find("=TODAY()-1", , xlFormulas, xlWhole)
        Range(m(2, 1), m(2, 1).End(xlDown)).Copy
    End With
    Sheets("Sheet2").Range("A5").PasteSpecial xlPasteValues
With Application
    .CutCopyMode = 0
    .ScreenUpdating = 1
End With
End Sub
 
Upvote 0
Run from the sheet where the table and formulas are.
VBA Code:
Sub FindMyFormula()
Application.ScreenUpdating = 0
Dim m As Range
    With ActiveSheet
        Set m = .UsedRange.Cells.Find("=TODAY()-1", , xlFormulas, xlWhole)
        Range(m(2, 1), m(2, 1).End(xlDown)).Copy
    End With
    Sheets("Sheet2").Range("A5").PasteSpecial xlPasteValues
With Application
    .CutCopyMode = 0
    .ScreenUpdating = 1
End With
End Sub
Thank you so much for this reply. I checked back a few times after posting my OP, but seem to have missed any notification that you replied afterwards. Top work, thank you.
 
Upvote 0
Glad I could help. Thank you for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,107
Messages
6,123,126
Members
449,097
Latest member
mlckr

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