ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clear Contents of all Sheets (https://www.excelbanter.com/excel-programming/407864-clear-contents-all-sheets.html)

[email protected]

Clear Contents of all Sheets
 
How would I clear the contents of all Sheets in my file? I can record
a macro that will clear the contents of a specific, but I have
multiple sheets and was wondering if there is a nice easy way

Newbie here

Thanks

Timmie

Mike H

Clear Contents of all Sheets
 
Hi,

If you going to do that why not simply delete the workbook. But if you want
another method use this. BEWARE it will delete everything so make sure thats
what you want. Alt+Fll to open Vb editor. Right click a worksheet tab, view
code and psate this in.

Sub clearall()
Dim ws As Worksheet
For x = 1 To ThisWorkbook.Worksheets.Count
Worksheets(x).UsedRange.ClearContents
Next
End Sub

Mike

" wrote:

How would I clear the contents of all Sheets in my file? I can record
a macro that will clear the contents of a specific, but I have
multiple sheets and was wondering if there is a nice easy way

Newbie here

Thanks

Timmie


[email protected]

Clear Contents of all Sheets
 
Thank you Mike that works a dream. Didn't want to delete the
worksheets as I have formats setup, so each week I copy in different
data (but require the same formats)

Tim

Dana DeLouis

Clear Contents of all Sheets
 
Once your workbook is clear, see if saving your workbook as a "Template"
might be an option for you.

--
Dana DeLouis

wrote in message
...
Thank you Mike that works a dream. Didn't want to delete the
worksheets as I have formats setup, so each week I copy in different
data (but require the same formats)

Tim



Mike H

Clear Contents of all Sheets
 
Hi,

Glad that helped and thanks for the feedback. BTW my response was a cut from
another sub and I included this line which isn't necessary
Dim ws As Worksheet

Mike

" wrote:

Thank you Mike that works a dream. Didn't want to delete the
worksheets as I have formats setup, so each week I copy in different
data (but require the same formats)

Tim



All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com