For Each Next

D

Darrin Henshaw

I'm feeling like a dummy at the moment. I'm using the For Each statement
to cycle through all sheets in the activeworkbook, and perform actions.
However, I have not used them befoer, and need help. This is what I
have:

Dim wksht As Worksheet
Application.ScreenUpdating = False
For Each wksht In ActiveWorkbook

'code to perform actions

Next wksht

But I get the error, "Object doesn't support this property or method".
Help! Thanks.
 
D

Danny@Kendal

Darrin Henshaw said:
I'm feeling like a dummy at the moment. I'm using the For Each statement
to cycle through all sheets in the activeworkbook, and perform actions.
However, I have not used them befoer, and need help. This is what I
have:

Dim wksht As Worksheet
Application.ScreenUpdating = False
For Each wksht In ActiveWorkbook

'code to perform actions

Next wksht

But I get the error, "Object doesn't support this property or method".
Help! Thanks.

Does this help?

For Each wksht in ActiveWorkbook.Worksheets
' insert your code here
next wksht
 
D

Darrin Henshaw

At least I don't get the error now. But what does happen is that the
actions I need to perform are only happening in the activeworksheet, not
any of the others. Here's an update to the code:

Dim wksht As Worksheet
Application.ScreenUpdating = False

For Each wksht In ActiveWorkbook.Worksheets

Point to note, this same thing happens if I use Sheets, instead of the
ActiveWorkbook. Thanks.
 
G

Guest

Are you performing those actions on the wksht object? i.e. wksht.cells or
wksheet.range, etc.?
 
D

Darrin Henshaw

I guess the actions are on the wksht.Cells object, since I'm inserting a
set number of rows.
 
D

Don Guillett

this should do it
Sub insertrowsinallsheets()
For Each w In Worksheets
w.Cells(1, 1).Resize(3, 1).EntireRow.Insert
Next
End Sub
 

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

Similar Threads

Auto footers on multiple pages 5
Doesn't recognize worksheet 2
DisplayHeadings 2
Autofilter (on/off) 1
Inconsistent macro behavior 2
FOR EACH statement 17
Sheets or Worksheets 2
Runtime error 57121 5

Top