VBA Loop through All Sheets Except Sheet1

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,176
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I need a way to loop throught all sheets except for Sheet1 and delete all of the used range except the header row. There are 6 worksheets. Can someone please help me.

Thanks in advance.
Stephen
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try...

Code:
Option Explicit

Sub test()

    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Sheet1" Then
            With ws.UsedRange
                .Resize(.Rows.Count-1).Offset(1, 0).ClearContents
            End With
        End If
    Next ws
    
End Sub
 
Last edited:
Upvote 0
With only 6 sheets, why not just do each one? Do you really need a loop??

Code:
Sheet1.Range("2:" & Sheet1.Rows.Count).Clear
Sheet2.Range("2:" & Sheet2.Rows.Count).Clear
Sheet3.Range("2:" & Sheet3.Rows.Count).Clear
Sheet4.Range("2:" & Sheet4.Rows.Count).Clear
Sheet5.Range("2:" & Sheet5.Rows.Count).Clear
Sheet6.Range("2:" & Sheet6.Rows.Count).Clear
 
Upvote 0
Heh! Or combine your two methods
Code:
Option Explicit
Sub test()
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Sheet1" Then
            ws.Rows("2:" & ws.Rows.Count).Clear
        End If
    Next ws
End Sub

Love the diversity of VBA :)
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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