I "DO" have a "DO"

  • Thread starter Thread starter Marie Lavoie
  • Start date Start date
M

Marie Lavoie

Hi, I have a macro that was once working...

It looks like this:

Sub LectureCode()

i = 5 'initialization du compteur
Sheets("Principale").Select

'Lecture du code
Do While Range("A" & i) <> Empty

(... here I have many code lines...)

Loop

But when I run it, it highlights the word Loop and says it has no "Do"

The only things I changed since the time it was working are lines of code
between this Do and Loop and I have not entered a "Loop" in there.

....Help?

Also, what is the difference between Do While ... Loop and While ... Wend

Marie
 
Hi
you probably have an additional loop or other end statement in your
other 'many code lines'
 
Marie,

Most likely, the error is that you are missing or have an extra
"End If" or other "End" statement in the code that you omitted.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
nope

Chip Pearson said:
Marie,

Most likely, the error is that you are missing or have an extra
"End If" or other "End" statement in the code that you omitted.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Hi
to be honest this answer won't help you to get a more specific response
:-)
How should we help you finding this error if we don't have more
information. So if your macro is not that long post the omitted lines.
I'm (and I think the same is true for Chip) quite sure that there's an
additional line of code (e.g. 'End', 'End if', 'Loop', etc.) which does
NOT have an opening statement

You may check this by yourself by identing each loop / if clause
 
Could be anything that unbalances your structure. Certainly an error on
your part.

See Above

None
 
here you go:
I guess my Select Case doesn't have the good syntaxe...

'Déclaration des variables
Dim i As Integer 'compteur
Dim NOCIBC As String ' No du dossier à la CIBC
Dim ND As String ' Notre numero de dossier
Dim Nom As String ' Nom du débiteur
Dim DateO As Date ' Date ouverture
Dim DateR As Date ' Date recouvrement
Dim Montant As Currency ' Montant du recouvrement

Sub LectureCode()

i = 5 'initialization du compteur
Sheets("Principale").Select

'Lecture du code
Do While Range("A" & i) <> Empty

NOCIBC = Range("B" & i)
ND = Range("C" & i)
Nom = Range("D" & i)
DateO = Range("E" & i)
DateR = Range("F" & i)
Montant = Range("G" & i)

---------------- beginning of new text-----------------------
'Série de tests
Select Case Range("A" & i)
Case "CLS"
Sheets("CLS").Select
Case "CLU"
Sheets("CLU").Select
Case "PLC"
Sheets("PLC").Select

------------------end of new text--------------------------------

'Inscription des données
Range("A14").Select ' Première ligne des données de
facture
Selection.EntireRow.Insert ' Insertion une ligne
Range("A14").FormulaR1C1 = NOCIBC
Range("B14").FormulaR1C1 = ND
Range("C14").FormulaR1C1 = Nom
Range("D14").FormulaR1C1 = DateO
Range("E14").FormulaR1C1 = DateR
Range("G14").FormulaR1C1 = Montant

'Préparation à la prochaine boucle
i = i + 1
Sheets("Principale").Select

Loop
End Sub
 
OH.... End Select... *sigh*
Not used to those "End ..." Lol, Used to C++ ;-)
Everything is ok. Thank you anyway!

Marie
 
Nope!

or

You never end the select case construct

see original comment:
Could be anything that unbalances your structure. Certainly an error on
your part.

Since the case structure is not terminated, a Loop command is unexpected.


Select Case Range("A" & i)
Case "CLS"
Sheets("CLS").Select
Case "CLU"
Sheets("CLU").Select
Case "PLC"
Sheets("PLC").Select

End Select
 

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