Clear contents in table but leave columns with formulas

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
442
Office Version
  1. 365
Platform
  1. Windows
Hi Guys,

I have 2 tables one named 'Steve' and the Other named 'Dave'.

Is there a way to use VBA to clear the contents of both tables but leave the formulas in columns R,S,T,U,V. At the moment i just select all rows from row 3 down (leaving the heading and row 2) and delete . I then paste the new data into A2 as values and the formulas in R,S,T,U,V auto copy down.

Thanks



<colgroup><col><col><col><col><col span="3"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hey, how about something like this:

Code:
Sub ClearNonFormulaeSteveAndDave()
    Dim cell As Range
    Dim rngSteve As Range
    Dim rngDave As Range
    Set rngSteve = Range("Steve")
    Set rngDave = Range("Dave")
        For Each cell In rngSteve
            If cell.HasFormula = False Then
                cell.ClearContents
            End If
        Next cell
        For Each cell In rngDave
            If cell.HasFormula = False Then
                cell.ClearContents
            End If
        Next cell
End Sub

I'd save your work before testing it but it should delete all non formula cells from the tables "Steve" and "Dave".
 
Upvote 0

Forum statistics

Threads
1,214,815
Messages
6,121,715
Members
449,049
Latest member
THMarana

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