Keeping data in previous worksheets

jesDav

New Member
Joined
Mar 13, 2024
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a workbook at work that we add a new new sheet every day. We just copy the old sheet so that as we update the data in separate spreadsheets it updates in the new sheet (it just copys cells from one sheet to another, not very advanced). Is there a VBA I can put in to keep the previous days data from changing, so we can track every days numbers, since we just reuse the formulas. Or even an easier and more efficient way to do this all?

Thanks for any input!

cashsheet snippit.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
try doing it manually... 1. copy to new workbook. 2. go back to old workbook. 3. select all in old workbook, copy, paste special, values. you can also use VBA, 4. now everything in old workbook are values. VBA is below, if you want to try it. It was all done using Record Macro. Record Macro is super easy. But in this case, there were manual changes to the code. both versions are included. you can line up both versions side-by-side and see exactly what was changed. Essentially, the change is the sheet name, and using cell E1 as the variable to name the old sheet. hope this helps. - cheers!

VBA Code:
Sub Macro1_rewritten_MACRO_EXAMPLE()
'''assume your cell E1 is empty and can be used to hold this formula temporarily
''''this is all done with Record Macro
    
   '''go to e1 in your existing sheet,
    Application.Goto Reference:="R1C5"
    ''enter today's date in text
    Selection.FormulaR1C1 = "=TEXT(NOW(),""yyyymmdd"")"
    Selection.Copy
    
    '''select sheet, rename it to old
    ActiveSheet.Select
    ActiveSheet.Name = "old"
    Sheets("old").Select
    Application.CutCopyMode = False
    
''choose old, copy (duplicate) it
    Sheets("old").Copy Before:=Sheets(1)
    
'''copied sheet is now named  old (2)
    ActiveSheet.Select
    
''re-name it to new
    ActiveSheet.Name = "new"
    
'''go back to old, select A to BZ, copy, paste special, values
    Sheets("old").Select
    Application.Goto Reference:="R1C1"
    ActiveCell.Columns("A:BZ").EntireColumn.Select
    Selection.Copy
    Application.CutCopyMode = False
    Calculate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.Goto Reference:="R1C1"
    Application.CutCopyMode = False
    Calculate
    
''go back to old, rename the sheet to be cellE1
    Sheets("old").Select
    Sheets("old").Name = Range("e1")
    
''go to new
    Sheets("new").Select
    Application.Goto Reference:="R1C1"
End Sub




Sub Macro2_RECORD_MACRO_EXAMPLE()
'''assume your cell E1 is empty and can be used to hold this formula temporarily
''''this is all done with Record Macro
    
   '''go to e1 in your existing sheet,
    Application.Goto Reference:="R1C5"
    ''enter today's date in text
    Selection.FormulaR1C1 = "=TEXT(NOW(),""yyyymmdd"")"
    Selection.Copy
    
    '''select sheet, rename it to old
    Sheets("Sheet1").Select
    Sheets("Sheet1").Name = "old"
    Sheets("old").Select
    Application.CutCopyMode = False
    
''choose old, copy (duplicate) it
    Sheets("old").Copy Before:=Sheets(1)
    
'''copied sheet is now named  old (2)
    Sheets("old (2)").Select
    
''re-name it to new
    Sheets("old (2)").Name = "new"
    
'''go back to old, select A to BZ, copy, paste special, values
    Sheets("old").Select
    Application.Goto Reference:="R1C1"
    ActiveCell.Columns("A:BZ").EntireColumn.Select
    Selection.Copy
    Application.CutCopyMode = False
    Calculate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.Goto Reference:="R1C1"
    Application.CutCopyMode = False
    Calculate
    
''go back to old, rename the sheet to be cellE1
    Sheets("old").Select
    Sheets("old").Name = "cellE1"
    
''go to new
    Sheets("new").Select
    Application.Goto Reference:="R1C1"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,126
Messages
6,123,198
Members
449,090
Latest member
bes000

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