I am building a program that other editors can use. I have a workbook where editors track data on the different services they offer. At the end of the year, I want a macro button they can click that first saves their workbook, then restores the spreadsheets to their original state so it is ready to use for the new year, and then prompts them to save it as the new year.
I have coded it to save the workbook, clear out all the data from the unlocked cells, refreshes the pivot table, and then prompts them to save as. The only part I don't know how to do is restore all the tables to just one row.
The spreadsheets contain multiple tables with just one row (and the header row) each. But when they click on new entry, a new row is added to the top of the table. By the end of the year, a table could have grown to 20 or so rows. I want to take it back down to one at the start of the new year. (Since they will want each new entry to be on the top.)
Quarter 1 - Quarter 4 worksheets each contain 5 named tables. On quarter 1: ServiceTable1, ServiceTable2, ServiceTable3, ServiceTable4, ServiceTable5. On quarter 2: ServiceTable2.1, ServiceTable2.2, ServiceTable2.3, ServiceTable2.4, ServiceTable2.5 etc.
On the average hire rate worksheet, there is one table named hirerate.
I have coded it to save the workbook, clear out all the data from the unlocked cells, refreshes the pivot table, and then prompts them to save as. The only part I don't know how to do is restore all the tables to just one row.
The spreadsheets contain multiple tables with just one row (and the header row) each. But when they click on new entry, a new row is added to the top of the table. By the end of the year, a table could have grown to 20 or so rows. I want to take it back down to one at the start of the new year. (Since they will want each new entry to be on the top.)
Quarter 1 - Quarter 4 worksheets each contain 5 named tables. On quarter 1: ServiceTable1, ServiceTable2, ServiceTable3, ServiceTable4, ServiceTable5. On quarter 2: ServiceTable2.1, ServiceTable2.2, ServiceTable2.3, ServiceTable2.4, ServiceTable2.5 etc.
On the average hire rate worksheet, there is one table named hirerate.
Code:
Sub NewYear()
Dim cell As Range, Sht As Worksheet
ActiveWorkbook.Save
'right here I want to then have it take every table on every worksheet except the Setup Page and Lists and delete all rows except the first
' and the header row
'this part of the code then deletes all the data left in the one row so it is cleared and ready for new data
For Each Sht In ThisWorkbook.Worksheets
If Sht.Name <> "Setup Page" And Sht.Name <> "Lists" Then
For Each cell In Sht.UsedRange
If cell.Locked = False Then cell.Value = ""
Next cell
End If
Next Sht
'then it refreshes the pivot table and prompts a save as
Call UnprotectRefresh
Call filesave
End Sub
Last edited: