Start Do/Loop within conditional statement


J

jamasm2010

Hi,
Is it possible to start a Do/Loop with a conditional statement? The code I have is:

If Education = False Then
Class = Range("H" & LastRow).Value
Do While Cells(LastRow, 8).Value = Class And LastRow <> 1
Else
Do While LastRow <> 1
Class = Range("H" & LastRow).Value
End If

and this is nested in a For/Next routine. When I attempt to run it, I get a "Compile error: Else without If." There is a similar error if I try to use Select/Case routine. If what I'm trying to do isn't possible, then is there a work around to it?
Thanks,
James
 
Ad

Advertisements

C

Claus Busch

Hi,

Am Tue, 13 Jan 2015 10:56:58 -0800 (PST) schrieb (e-mail address removed):
If Education = False Then
Class = Range("H" & LastRow).Value
Do While Cells(LastRow, 8).Value = Class And LastRow <> 1
Else
Do While LastRow <> 1
Class = Range("H" & LastRow).Value
End If

what do you want to do into this loop? I cannot see a order to do
anything.


Regards
Claus B.
 
J

jamasm2010

Hi Claus,
I'm just trying to start the loop. If I comment out the conditional piece and one pair of the instructions on either side of the Else statement, it works great. On the first condition, if the employee list is to be run according to supervisor, then a report is generated by supervisor. On the second condition, the supervisor is irrelevant and all employess are listed alphabetically. The subroutine is quite large, but to outline the process a little more:

For Each c In Rng.Cells

'Set parameters and counters

If Education = False Then
Class = Range("H" & LastRow).Value
Do While Cells(LastRow, 8).Value = Class And LastRow <> 1
Else
Do While LastRow <> 1
Class = Range("H" & LastRow).Value
End If

'Extract data and format
'Error checking, too.

Loop

Next c
 
C

Claus Busch

Hi,

Am Tue, 13 Jan 2015 11:36:10 -0800 (PST) schrieb (e-mail address removed):
I'm just trying to start the loop. If I comment out the conditional piece and one pair of the instructions on either side of the Else statement, it works great. On the first condition, if the employee list is to be run according to supervisor, then a report is generated by supervisor. On the second condition, the supervisor is irrelevant and all employess are listed alphabetically. The subroutine is quite large, but to outline the process a little more:

I still don't know what you want to do.
Try:
If Education = False Then
Do
Class = Range("H" & LastRow).Value
Loop While Cells(LastRow, 8).Value = Class And LastRow <> 1
Else
Do
Class = Range("H" & LastRow).Value
Loop While LastRow <> 1
End If

And if it does not work please explain exactly what you want to do


Regards
Claus B.
 
Ad

Advertisements

J

jamasm2010

Thanks, Claus, but now it errors on the Loop statement at the bottom of thesub routine. The first conditional generates a report based upon the supervisor's name (Class)- so, it will loop as long as the supervisor's name stays the same. On the second conditional, the report is generated by the employee's surname without regard to the supervisor's name (Class). If worse comes to worse, I can always put the conditional at the top of the sub routine, duplicate the remainder of the module under a different name, and then have the conditional send the execution of the code to that subroutine.
 

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

Top