Loop thru worksheets(i)

  • Thread starter Thread starter Jim at Eagle
  • Start date Start date
J

Jim at Eagle

Dim i As Byte
i = 22
Do While i < 32
Worksheets(i).Range("J14:K28").ClearContents
i = i + 1
Loop

I have tried many ways but allways get one of several errors when the
worksheet line is run. Any help here will be greatly appreciated.
 
Sub clearsheets()
For i = 22 To 31 ' Sheets.Count
Sheets(i).Range("j14:k28").ClearContents
Next i
End Sub
 
Sub mersion()
Dim i As Integer
For i = 1 To 31
Worksheets(i).Activate
ActiveSheet.Range("J14:K28").ClearContents
Next
End Sub
 
Works fine for me - are you sure you have 32 sheets in your workbook?
 
Thanks for your help.
I get a runtime error 9 subscript out of range
there were two other suggestions to my request that when limited to sheets
22-32 i would get same error.
When allowing i to start at 1 it would happly work trashing a few extra
sheets.
Any suggestions?
excel 2003 xppro and there are more then 32 sheets.
 
I tried to use two nested DO While loops still would fail.
Then there was the following:

For i = 1 To 11
Worksheets("PReport " & i).Range("J14:K28").ClearContents
Next

I'm back in business, Thanks for your help.
I got where I was going but still would be nice to know why I couldn't go
the way I wanted to.
 
The only reason I can think of is that you had some chart sheets and I
should have suggested
worksheets.
instead of
sheets.
 

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

Back
Top