PDA

View Full Version : Worksheet Delete



drums4monty
02-13-2011, 07:59 AM
Hi All

I need to delete the contents of 63 worksheets in a workbook in a specific range, I wrote the following code but all it does is delete the first sheet 63 time and does not move onto the other sheets, can someone help/explain my problem.

For i = 2 To 63
Set sh = Worksheets(i)
Range("C5:G45").Select
Selection.ClearContents
Range("A2").Select
Next i

Kind regards

Alan

Tinbendr
02-13-2011, 08:14 AM
For i = 2 To 63
Worksheets(i).Range("C5:G45").ClearContents
Next i


David

drums4monty
02-13-2011, 08:21 AM
Many Thanks Tinbendr

mdmackillop
02-13-2011, 09:12 AM
If the code applies to all sheets after sheet 1,
For i = 2 To Sheets.Countwill make it more flexible.

Wireless Guy
02-13-2011, 11:08 PM
You may also want to try

For EACH sheet in Sheets

Sheet.range("C5:G45").Clearcontents

Next Sheet


The For Each construct is a useful one to know.