Clear Contents on Multiple Worksheets

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I'm trying to clear the contents on multiple worksheets, from row 2 through the last row. I'm running into an issue where I'm trying to skip the worksheet if row 2 is already empty. Here's my code. I'm getting a Next Without For error message.

Code:
Sub ClearData()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In Worksheets
    If Not ws.Name = "Summaries" And Not ws.Name = "Consolidated" And Not ws.Name = "Variables" Then
        If ws.FilterMode = True Then
            ws.ShowAllData
        Else
        End If
        If ws.Range("A2").Value <> "" Then
        With ws.Range("A2:P" & ws.Range("A2" & Rows.Count).End(xlUp).Row)
            .ClearContents
        End With
        Else
    End If
Next ws
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello Reberryjr,

Try the following version of your code:-

Code:
Sub ClearData()

Dim ws As Worksheet

Application.ScreenUpdating = False

For Each ws In Worksheets
             If ws.Name <> "Summaries" And ws.Name <> "Consolidated" And ws.Name <> "Variables" Then
             If ws.Range("A2") <> "" Then
             ws.UsedRange.Offset(1).ClearContents
             End If
       End If
Next ws

Application.ScreenUpdating = True

End Sub

Test it in a copy of your workbook first.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
You're welcome. I'm glad that I was able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,453
Members
449,161
Latest member
NHOJ

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