Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default clear all sheets code

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default clear all sheets code

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default clear all sheets code

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 :
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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default clear all sheets code

On Wednesday, November 12, 2014 9:57:01 PM UTC-6, Matthew Dyer wrote:
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?

changing cells.delete to .usedrange.rows.delete may be faster
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear all including objects without deleting sheets Curt Excel Programming 0 April 16th 10 02:42 PM
Clear all including objects without deleting sheets Chip Pearson Excel Programming 0 April 15th 10 09:13 PM
Clear Contents of all Sheets [email protected] Excel Programming 4 March 18th 08 09:17 AM
Clear entire rows below last row of data in col A except in 1st 3 sheets Max Excel Programming 6 January 7th 08 10:33 AM
Clear Sheets in Excel Emily[_3_] Excel Programming 11 July 27th 06 04:23 PM


All times are GMT +1. The time now is 12:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"