Clear additional rows when overwriting table data in Excel 2016 - excel

I have a daily task of overwriting data in a table. The number of rows fluctuates day-to-day, so I have to scroll to the bottom of the table to check if there are less rows than the overwritten data. If there are, I have to highlight the additional rows of "old" data and delete them. I'm trying to automate this process to either a) automatically delete old rows upon overwriting of table data or, b) create some sort of "alert" signaling there are old rows that need to be deleted. Thank you in advance.

For anyone interested, I've created a macro and button to delete all rows from the 6 tables. Here is an example of the code that deletes all rows from one table. I copy and pasted this with/end with statement for each of the 6 tables into one macro.
With Sheet1.ListObjects("Table3")
If Not .DataBodyRange Is Nothing Then
.DataBodyRange.ClearContents
.DataBodyRange.Delete
End If
End With

Related

Is there a way to add one new row to a selected range each time code is run? And also save this upon exit?

I am wondering how I can increase a selection range by 1 row each time the code is run but for it to always increase selection by 1.
What happens is I get new data which is pasted into a table and the pivot table is refreshed. Upon refresh, there are new entries in the pivot table. I would like to select a certain range of cells when new data is added and copy this selection to another page (but not all the new data as some of the data is unreliable)
Code so far is:
Sub A_Data_Refresh_Select ()
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Range("B19:G509").Select
I know this just simply selects the range, but it was just done using a macro so I could edit it. Ideally I would like to select all the data apart from the last 2 or 3 rows each time. Maybe that is an easier way to think of it?
Thanks for the help.

How can I edit the text of Excel table column headers that are the same across all sheets in the workbook?

I have an Excel workbook that has ~100 sheets in it, and each sheet is a table whose headers are exactly the same. I have edited the text of the headers in my blank "to copy" sheet, but I now need to copy those changes across each and every existing sheet (the rest of which have data in them that I cannot lose/change).
I have already tried using Shift+click to select all the sheets, but cannot edit the header because they are already formatted as tables and I get the "Cannot make changes to a table or XML mapping when multiple sheets are selected." error. So I either need a way to select every sheet and make them not a table anymore (temporarily) so that I can make the bulk change, or find some other way of doing this change while they are still a table.
Thanks for your time and advice.
Mirror a single table to multiple sheets in excel using vba
You might see this solution, As it is not possible to change multiple sheets while they are formatted as tables .. you might do the changes if your sheets are not formatted as sml or tables.

Deleting and reuploading data table without references having #REF issues [Excel]

I created a VBA script that deletes an existing data table (named Data) and replaces it with a new version (that has the same headers and is named Data). I have a lot of formulas and charts that rely on this table and was wondering how I can keep the references working after changing the table (so that pivot tables, formulas, and array formulas update automatically when I update the Data table).
Below are some pictures of the problems I am running into:
Pivot tables not updating with new data
Data turning to #REF! after deleting Data table
Likely what is happening is that once you delete the table (based on your definition of the problem), the link to the chart is then lost.
Rather than delete the table (as a whole), delete the individual data rows:
Sub RemoveTableBodyData()
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Table1")
'Delete Table's Body Data
If tbl.ListRows.Count >= 1 Then
tbl.DataBodyRange.Delete
End If
End Sub
from: The VBA Guide To ListObject Excel Tables
This should otherwise keep the table reference intact for the chart. FYI: because the data has been updated, you may want to make a call out to refresh any dependent pivots and charts, otherwise it may not be clear the data has updated... I might make the call to refresh once after the data set has been cleared, then again after the update... this will make it clear the pivots/charts have been updated.
Good Luck.
Use a dynamic named range as the pivottable source. Then only remove data below the headers.Don't overwrite or change the headers
Or use your existing table but again keep the headers and only delete rows from beneath (e.g. ActiveSheet.ListObjects(1).DataBodyRange.Delete
) . If you delete the entire table then any dependant formulas will error as the reference is no longer valid. That table no longer exists.
Or have code that creates everything for you.
So, why not change all the formulae to text by using edit/replace "=" with "xyxyxy" and then do whatever with your data as everything is just text.
Once done replace "xyxyxy" with "=" and the formulae work again - works fine with my sheets and I have a LOT of formulae in them.
Late to the game but a simple solution I found was to change the table reference to use indirect. Example Table1[Field1] changes to indirect("Table1[Field1]").

Access data export to excel: 1 issue- count

I have a button in access that runs queries and dumps the info into an Access table, then that table is used to populate an excel sheet. This excel sheet is then linked to a 2nd worksheet (B) that has the formatting needed to submit for state reporting. I am having an issue that I need to fix with my process.
I have a record count- currently on the top of the formatted worksheet, but it has to be at the bottom of my formatted worksheet- it needs to be in the A column on the row after the last entry. How do I do this as since there's no set row to show record count? 1 report it may be 5, next report may be 35 rows.
I do the record count from the original (un-formatted) excel sheet that has the data dumped from Access, so it's accurate. I just need help moving it! end
Thanks.

Pivot and automatic inclusion of new row nr data in Excel

I needed some guidance from your more experience excel pros. I have two sheets in my excel file.
Data
Pivot Data
I have my data in the "Data" sheet and I have created a Pivot sheet for sheet Data.
Everyweek, I delete my data in the Data sheet and paste new data.With this, my rows become more. to update my pivots, I need to go to data source and update it so it include all the rows.
Is there something I can do or write so the pivots automatically adjust to the size of the new paste data in the Data sheet?
If before deleting the data, it was on row 400, I then paste new data and the row number is now 800, how can I automate this process rather than going to each pivot and updating manually to the new row number so it captures all the new data?
Change your Data Source range to exclude row numbers, so say:
Sheet3!$A:$D
instead of:
Sheet3!$A1:$D400
This will however introduce a row in your PT of (blank) (if not already present there), though you might filter to hide that row.

Resources