Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looping through selected worksheets and delete a range (e.g., A2:D15)

I am trying to loop through the selected sheets and clear the contents
of Range("A2:D15") of all the selected sheets. When I run this code,
it only clears the content of Sheet3. Thank you in advance for your
assistance.
================================================== =========================

Sub ClearSheets

Dim sht As Worksheet

Application.ScreenUpdating = False

Sheets(Array("Sheet3", "Sheet5", "Sheet6", "Sheet8")).Select

For Each sht In ActiveWindow.SelectedSheets

Range("A2:D15").ClearContents

Next sht

Application.ScreenUpdating = True

End Sub
================================================== ===========================

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Looping through selected worksheets and delete a range (e.g., A2:D

Maybe something like this
Sub ClearSheets()
Dim x As Object
Sheets(Array("Sheet3", "Sheet5", "Sheet6", "Sheet8")).Select
For Each x In ActiveWindow.SelectedSheets
x.Range("A2:D15").ClearContents
Next x
End Sub

" wrote:

I am trying to loop through the selected sheets and clear the contents
of Range("A2:D15") of all the selected sheets. When I run this code,
it only clears the content of Sheet3. Thank you in advance for your
assistance.
================================================== =========================

Sub ClearSheets

Dim sht As Worksheet

Application.ScreenUpdating = False

Sheets(Array("Sheet3", "Sheet5", "Sheet6", "Sheet8")).Select

For Each sht In ActiveWindow.SelectedSheets

Range("A2:D15").ClearContents

Next sht

Application.ScreenUpdating = True

End Sub
================================================== ===========================


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
Delete rows at the same time from selected worksheets Filo Excel Programming 3 May 5th 07 02:41 PM
Looping: Search Range in Multiple Selected Worksheets, Copy/Paste ryguy7272 Excel Programming 6 April 2nd 07 04:50 PM
Delete selected range RW Excel Programming 2 December 12th 05 12:55 PM
delete every nth row in selected range cwinters Excel Discussion (Misc queries) 1 July 6th 05 08:17 PM
Looping down a Range to delete entire row sportsguy Excel Programming 3 July 1st 05 04:50 PM


All times are GMT +1. The time now is 12:23 PM.

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

About Us

"It's about Microsoft Excel"