Amend Code to clear Data using Current Region

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the following code below to clear data on sheets 2 onwards using Current Region

The range is from A6 to last row containing data in Col S

Cols I & Q are a blank column so data is only cleared up to Col H


It would be appreciated if someone could kindly amend my code

Code:
 Sub Clear_+Data()
Dim I As Long
For I = 2 To Sheets.Count
    Sheets(I).Cells(6, 1).CurrentRegion.ClearContents
Next I
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,
try

VBA Code:
Sub Clear_Data()
    Dim i As Long, lastrow As Long
    
    For i = 2 To Worksheets.Count
        With Worksheets(i)
            lastrow = .Cells(.Rows.Count, "S").End(xlUp).Row
            .Cells(6, 1).Resize(lastrow - 5, 19).ClearContents
        End With
    Next i
End Sub

Dave
 
Upvote 0
Solution
welcome - glad suggestion helped - appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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