PDA

View Full Version : [SOLVED] Clearing contents of all worksheets in a excel workbook



Rampage123
04-01-2014, 06:16 AM
Hi all,

Is there a simple VBA code to clear contents for all worksheets in a excel workbook?

I have nearly 25-30 worksheets in a tool which need to be cleared before running the tool

Thanks in advance for the help

Kenneth Hobs
04-01-2014, 07:03 AM
Always test code on backup copies of data.

Sub ClearContents()
Dim ws As Worksheet
For Each ws In Worksheets
ws.UsedRange.ClearContents
Next ws
End Sub

Rampage123
04-01-2014, 07:17 AM
Always test code on backup copies of data.

Sub ClearContents()
Dim ws As Worksheet
For Each ws In Worksheets
ws.UsedRange.ClearContents
Next ws
End Sub

thanks Kenneth. That works like a treat.

Also, I have 28 sheets in my tool out of which I have to clear contents in 25 sheets. The other 3 sheets should remain untouched. Is there a smart way to do this rather than writing code for each sheet?

EirikDaude
04-01-2014, 07:52 AM
Sub ClearContents()
Dim ws As Worksheet
For Each ws In Worksheets
If Not (ws.Name = "FirstSheetToSkip" Or ws.Name = "SecondSheetToSkip" Or ws.Name = "ThirdSheetToSkip") Then
ws.UsedRange.ClearContents
End If
Next ws
End Sub