clear all sheets code

M

Matthew Dyer

i'm using the following code to clear/delete anything and everything in already existing sheets:
Sub wbclear()
Dim N As Long
Dim ttl As Long
ttl = ThisWorkbook.Worksheets.Count
For N = 1 To ttl
Worksheets(N).Cells.Delete
Next N
End Sub

what i'd also want is to have cell a1 selected but adding range("a1").select does not work, and i think it's simply because i'm never activating the sheets via code, just deleting the data held in the sheets. is there a bit of code i could use to select cells without activating the sheet?
 
I

isabelle

hi Matthew Dyer,

Sub test()
For Each sh In Worksheets
With sh
.Cells.Delete
End With
Next
End Sub

isabelle

Le 2014-11-12 22:56, Matthew Dyer a écrit :
i'm using the following code to clear/delete anything and everything in already existing sheets:
Sub wbclear()
Dim N As Long
Dim ttl As Long
ttl = ThisWorkbook.Worksheets.Count
For N = 1 To ttl
Worksheets(N).Cells.Delete
Next N
End Sub

what i'd also want is to have cell a1 selected but adding range("a1").select does not work, and i think it's simply because
i'm never activating the sheets via code, just deleting the data held in the
sheets. is there a bit of code i could use to select cells without activating
the sheet?
 
I

isabelle

sorry, i forgot to select cell A1

Sub test()
For Each sh In Worksheets
With sh
.Cells.Delete
Application.Goto .Cells(1, 1)
End With
Next
End Sub

isabelle

Le 2014-11-12 23:20, isabelle a écrit :
 
D

dguillett

i'm using the following code to clear/delete anything and everything in already existing sheets:
Sub wbclear()
Dim N As Long
Dim ttl As Long
ttl = ThisWorkbook.Worksheets.Count
For N = 1 To ttl
Worksheets(N).Cells.Delete
Next N
End Sub

what i'd also want is to have cell a1 selected but adding range("a1").select does not work, and i think it's simply because i'm never activating thesheets via code, just deleting the data held in the sheets. is there a bitof code i could use to select cells without activating the sheet?
changing cells.delete to .usedrange.rows.delete may be faster
 
G

Gord Dibben

I see the Horns got the job done yesterday.

Maybe see Aggies in an all Texas bowl?

Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top