Setting startup point for a for each statement

  • Thread starter Thread starter Daniel Kvisten
  • Start date Start date
D

Daniel Kvisten

Hi,

I try to get a For Each statement to start at worksheet #3 and search
trough the next worksheets.

My statement ( that works from sheet #1 troughout the workbook ):

dim wks as worksheet
for each wks in worksheets

My question is therefor how to modify the for each statement?

Regards
Daniel
 
Hi Daniel
you may try
dim i
for i = 3 to worksheets.count
msgbox worksheets(i).name
next
 
Daniel,

There is a 'gotcha' with Frank's solution. That is that the index number,
which Frank uses, refers to the order of sheets, which has an initial
correlation to it's name, but this is easily changed. So it is not
necessarily true that Worksheets(3) is the same as Worksheets("Sheet3").

Take care.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Hi daniel

try the following "if statement" in the for each loop:
'--------------------------------
Dim wks As Worksheet

For Each wks In Worksheets
If wks.Index > 2 Then
'your code you want to execute
MsgBox "In the loop " & wks.Name
End If
Next wks
'---------------------------------

Hope this helps!
Tanner Dhesi
(e-mail address removed)
 

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