Fonction print avec condition

Rayan75008 Messages postés 7 Date d'inscription lundi 25 décembre 2000 Statut Membre Dernière intervention 31 octobre 2008 - 31 oct. 2008 à 10:42
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 - 1 nov. 2008 à 18:01
Bonjour,

J'ai développé un code source me permettant d'imprimer un onglet d'un fichier excel qui est bati en ligne, colonne avec une condition d'impression uniquement si une cellule est renseignée. Mon code fonctionne bien mais il imprime tout!!! je ne comprends pas pourquoi même en changeant de type de condition ou de colonne ou se trouve la cellule à lire!!!

Quelqu'un a t il une idée SVP!!! MERCI d'avance!

Voici mon code :

Private Sub CommandButton1_Click()
Dim intMsg As Integer
Dim strReponse As String
Dim Responsel As Long
Dim r As Long, c As Long
Dim f As Long
f = FreeFile
'colonne h
Dim ha As Long
Dim hb As Long
Dim hc As Long
'colonne i
Dim ia As Long
Dim ib As Long
Dim ic As Long
'colonne j
Dim ja As Long
Dim jb As Long
Dim jc As Long
'colonne k
Dim ka As Long
Dim kb As Long
Dim kc As Long
'colonne l
Dim la As Long
Dim lb As Long
Dim lc As Long
'colonne m
Dim mb As Long
Dim mc As Long
'colonne n
Dim nb As Long
Dim nc As Long
'colonne o
Dim ob As Long
Dim oc As Long
'colonne p
Dim pb As Long
Dim pc As Long
'colonne q
Dim qb As Long
Dim qc As Long
'colonne r
Dim rb As Long
Dim rc As Long
'colonne s
Dim sb As Long
Dim sc As Long
'colonne t
Dim tb As Long
Dim tc As Long
'colonne u
Dim ub As Long
Dim uc As Long
'colonne v
Dim vb As Long
Dim vc As Long
'colonne w
Dim wb As Long
Dim wc As Long
'colonne x
Dim xa As Long
Dim xb As Long
Dim xc As Long
'colonne y
Dim yb As Long
Dim yc As Long
Open "c:\temp\upload.dat" For Output As #f
intMsg = MsgBox("Voulez Vous lancer l'extration?", vbOKCancel)
If intMsg = 1 Then
      r = 4
        Do
           If Cells(r, 1) = 1 Then _
ha = 20
ia = 15
ja = 4
ka = 2
la = 1
xa = 60


hb = Len(Cells(r, 8))
ib = Len(Cells(r, 9))
jb = Len(Cells(r, 10))
kb = Len(Cells(r, 11))
lb = Len(Cells(r, 12))
mb = Len(Cells(r, 13))
nb = Len(Cells(r, 14))
ob = Len(Cells(r, 15))
pb = Len(Cells(r, 16))
qb = Len(Cells(r, 17))
rb = Len(Cells(r, 18))
sb = Len(Cells(r, 19))
tb = Len(Cells(r, 20))
ub = Len(Cells(r, 21))
vb = Len(Cells(r, 22))
wb = Len(Cells(r, 23))
xb = Len(Cells(r, 24))
yb = Len(Cells(r, 25))


hc = ha - hb
ic = ia - ib
jc = ja - jb
kc = ka - kb
lc = la - lb
mc = ha - mb
nc = ha - nb
oc = la - ob
pc = ha - pb
qc = ha - qb
rc = la - rb
sc = ha - sb
tc = la - tb
uc = ha - ub
vc = ha - vb
wc = ha - wb
xc = xa - xb
yc = ha - yb




                Print #f, Cells(r, 8) & Space(hc) & Cells(r, 9) & Space(ic) & _
                     Cells(r, 10) & Space(jc) & Cells(r, 11) & Space(kc) & Cells(r, 12) & Space(lc) & Cells(r, 13) & Space(mc) & _
                     Cells(r, 14) & Space(nc) & Cells(r, 15) & Space(oc) & Cells(r, 16) & Space(pc) & Cells(r, 17) & Space(qc) & _
                     Cells(r, 18) & Space(rc) & Cells(r, 19) & Space(sc) & Cells(r, 20) & Space(tc) & Cells(r, 21) & Space(uc) & _
                     Cells(r, 22) & Space(vc) & Cells(r, 23) & Space(wc) & Cells(r, 24) & Space(xc) & Cells(r, 25) & Space(yc)
                                            r = r + 1
                         Loop Until Cells(r, 8) = vbNullString ' tests de dernière ligne ( cellule 1 vide ...)
            strReponse = MsgBox("Fin de l'extraction")
           
            Else
    End If
   
Close #f


End Sub

3 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
31 oct. 2008 à 12:26
vire le _ après ton Then
0
Rayan75008 Messages postés 7 Date d'inscription lundi 25 décembre 2000 Statut Membre Dernière intervention 31 octobre 2008
31 oct. 2008 à 13:53
Je l'ai enlevé, il m'affiche ensuite que "Erreur de compilation: Boucle sans Do"
0
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
1 nov. 2008 à 18:01
Bonjour,
Et pour cause !
Tu utilises en effet un loop qui est censé clore une routine iyverte par un Do ! (voir ton aide en ligne sur l'utilisation de Do ...Loop) !!
Où est-il; ton Do ????
0
Rejoignez-nous