Delete selected Range in selected Sheets

JorgenKjer

Board Regular
Joined
Aug 1, 2016
Messages
65
Office Version
  1. 2013
Platform
  1. Windows
Deleteselected Range in selected Sheets


Cananyone help with a code that deletes a Range starting in "A7" to bedeleted in all Sheets except two in the workbook?
Rangecan vary in number of Rows.
Afterall Sheets are deleted, cell "A7" must be active on all sheets thathave been deleted

I'vetried this code but it stops after Case Else with a Run-time error”1004” Selectmethod of Range class failed.

There issurely a better way to choose Rank "A7: K400". I just don't know how.Since only one sheet will have data until Row 400

SubClearLoop()

Dim wscl As Worksheet

For Each wscl In ActiveWorkbook.Worksheets
Select Case wscl.Name
Case "Data", "FrontPage"
' do nothing
Case Else
wscl.Range("A7:K400").Select
Application.CutCopyMode = False
Selection.Clear
Range("A7").Select
End Seleect

Nextwscl

End Sub


RegardsJorgen

 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You actually need to select each page first, if you want to select a cell on it.
Try this:
Code:
Sub ClearLoop()

Dim wscl As Worksheet

For Each wscl In ActiveWorkbook.Worksheets
    Select Case wscl.Name
        Case "Data", "FrontPage"
            ' do nothing
        Case Else
            wscl.Activate
            wscl.Range("A7:K400").Clear
            wscl.Range("A7").Select
    End Select
Next wscl

End Sub
 
Upvote 0
Hi Joe4

Thank you

The code runs perfectly now

Greeting Jorgen
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

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