Clearing table without destroying formulas

nmgmarques

Board Regular
Joined
Mar 1, 2011
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hi all.

Trying to clear Table1 in Worksheet "Análise" without destroying my formulas or existing data validation. This is the original look.
GFiQxnV.png

So far I have tried:
Code:
Sub ClearTables()
    With Worksheets("Análise").ListObjects("Table1")
        If Not .DataBodyRange Is Nothing Then
[B]            .DataBodyRange.SpecialCells(xlCellTypeConstants).ClearContents[/B]
        End If
    End With
End Sub
This clears only cells without formulas and doesn't destroy data validation, but doesn't delete rows nor blank out the cells with formulas.
Q3YavGB.png


Also tried:
Code:
.DataBodyRange.ClearContents
This cleared the entire table, left the data validation, but destroyed the formulas and didn't delete empty rows.
VorWl0n.png


And of course:
Code:
.DataBodyRange.Delete
This one is the closes I got. Deleted all rows except first, leaving it empty. Didn't remove data validation, but did destroy the formulas.
J2cMLPv.png


Can anyone suggest a way to clear, delete empty rows, but keep formulas and validation in first row?
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This will retain the formulas etc:

Code:
Sub deleteRows()
Dim LO As ListObject


Set LO = ActiveSheet.ListObjects(1)


LO.DataBodyRange.Rows.Delete


End Sub
 
Upvote 0
This will retain the formulas etc:

Code:
Sub deleteRows()
Dim LO As ListObject


Set LO = ActiveSheet.ListObjects(1)


LO.DataBodyRange.Rows.Delete


End Sub
I just tested it but sorry to say it deleted the formulas. :(
 
Upvote 0
That would suggest to me then that your formula columns are not set as Calculated Columns??
 
Upvote 0
That would suggest to me then that your formula columns are not set as Calculated Columns??

Ok, now you just lost me :P To the Googlemobile.

/reads furiously!

Ok I think I understand and I think they are calculated columns. In any case, this is the file in question. You can check it and let me know if I'm not understanding it correctly. You'll have to pause the VBA scripts to access the columns that are currently being jumped over.
The file.
 
Upvote 0
Your Table does retain the formulas.

Once you ran the macro did you enter a value into column B to see if the VLookup worked?
 
Upvote 0
Do me a favour, do the same thing as in the clip but once you enter a No Infor. Press F9

Does the VLookup populate?

If so, try changing calculations to auto.
 
Upvote 0
Do me a favour, do the same thing as in the clip but once you enter a No Infor. Press F9

Does the VLookup populate?

If so, try changing calculations to auto.

****, you are good. I was actually just popping over here to tell you that I had just noticed that for some reason it seems that my calculation options change to manual each time I press the button. Can't figure out why. But in any case, that was indeed the issue. It's all sorted out now. Just have to figure out why it keeps disabling the auto and setting to manual.
 
Upvote 0
You're Welcome.

I can't see anything in your code that would change it.

This setting is Application wide so do you have any other workbooks open?
 
Upvote 0

Forum statistics

Threads
1,224,215
Messages
6,177,172
Members
452,763
Latest member
WH12TTY

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