2 questions

  • Thread starter Thread starter uno@korsmaa
  • Start date Start date
U

uno@korsmaa

Hello gurus


1) How to programmatically check if a workbook is protected or not?


2) Does the For ...To .. Next loop have a syntax where I could run 2
different number ranges in the same loop. I will illustrate my question by a
fake "code".

For n = 1 To 10 And For n = 21 To 30
... do this
Next n

I came up with an idea where I would inside the loop, use an IF condition at
the beginning and let the loop ignore part of the numbers, but maybe there
is a direct way also.
 
Hi Uno,

Question 2
Not AFAIK
however, you could try

For N = 1 to 30
'do some thing
If N =10 then N = 20
Next

regards,
Don
 
1) See the answer to Sheldon's "Worksheet Protection" thread.

2) One way:

For n = 1 To 30
If n <= 10 Or n>=21
'... do this
End If
Next n

an alternate is to adjust n within the loop, but I don't recommend it on
general good programming principles:

For n = 1 To 30
'...do this
If n = 10 Then n = 20
Next n

Doing a null loop as in the first example won't take more than a few
microseconds.
 

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


Back
Top