Clear data on two different sheets with different ranges

Zahid0111

New Member
Joined
Mar 8, 2020
Messages
23
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a workbook with different sheets, when i try to clear some ranges through vba code, it gives me error, please help me with this.

VBA Code:
Private Sub CommandButton5_Click()

    Range("B13:F13").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("R13:S13").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("AG13:AH13").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A2").Select
    Sheets("RawDataBher").Select
    Range("A2:E2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("H3:AA3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("AL3:AO3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("AR3:AS3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Sheets("Bherkund").Activate
    Range("I7").Select

End Sub




error 1.1.PNG
error 1.PNG
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You don't need to activate the worksheet or select the range to clear the contents.

Worksheets("Bherkund").Range("A1:A10").ClearContents will clear the contents from the specified worksheet and range.

I hope that this helps.

Take care and stay safe.
 
Upvote 0
yes it clears but i want it should also clear below values in the range defined...as i have used .End(xldown)
 
Upvote 0
worksheets("Bherkund").Range("A10:A" & Cells(Rows.Count, "A").End(xlUp).Row).ClearContents

will clear the contents from cell A10 downwards.
 
Upvote 0
Hey..how can i mark this thread as "Solved" and also give you credit..thanks
 
Upvote 0
I've just found this from one of the moderators:

We don't mark threads as solved in this forum as it sometimes happens that an even better solution comes along later and we don't want to discourage that by marking a 'solved'.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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