Link to home
Start Free TrialLog in
Avatar of Jagwarman
Jagwarman

asked on

VBA to clear data from worksheets

I have a file that has over 30 different worksheets. Some of these have data I need to keep but the majority have data that needs to be cleared so that we can start collecting the current data and post on the sheets.

Could an expert provide me with VBA code that will clear data from all the sheets in the workbook except for those that I need to keep. There are currently 6 sheets that I need to keep so we can call them Sheet1, Sheet2 etc etc up to Sheet6

Many thanks
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Hi

You could use this macro and call it for each sheet you want

Sub DeleteSheetContetn()
    Cells.Select
    Selection.ClearContents
    Range("A1").Select
End Sub

Open in new window

HTH
Ivo Stoykov
Avatar of Phillip Burton
Phillip Burton

Define "clear"? Do you want to keep headers (and if so, which rows), page setup? Are there formulas already set up?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jagwarman

ASKER

Hi Phillip

in this case I need to clear the sheets completely headers and all

Regards
Then both Rory's and Ivo's solutions both work.
As I need to clear so many sheets Rory's is the better solution for me, but thank you all for your input