Problème de boucle avec for

Résolu
davsnoop -  
ShaBoo Messages postés 406 Statut Membre -
Bonjour,
Je n'arrive pas a faire une macro exel qui me conte le nombre de cellule non vide dans une colone.

Je fait la boucle suivante mais ca ne marche pas

Dim i As Integer
Dim var As Variant

i = 1
var = 1

For i = 1 To var
If Cells(i, 1) <> "" Then
var = i + 1

Else
Exit For

End If
Next i

2 réponses

  1. ShaBoo Messages postés 406 Statut Membre 50
     
    Bonjour,

    tu peux essayer ceci :

    Dim iLineRead As Integer
    Dim iNbLine As Integer
    Dim iNbCellNoEmpty As Integer
    
    iLineRead = 1
    iNbLine = Sheets(1).Range("A65536").End(xlUp).Row 
    iNbCellNoEmpty = 0
    
    
    Do Until iLineRead = iNbLine
        If Trim(Sheets(1).Cells(iLineRead, 1)) <> "" Then
            iNbCellNoEmpty = iNbCellNoEmpty + 1
        End If
    
        iLineRead = iLineRead + 1
    Loop
    
    MsgBox "Nombre de cellule non vide = " & iNbCellNoEmpty
    
    0
  2. ShaBoo Messages postés 406 Statut Membre 50
     
    Avec un For cela donnera ceci :

    Dim iLineRead As Integer
    Dim iNbLine As Integer
    Dim iNbCellNoEmpty As Integer
    
    iLineRead = 1
    iNbLine = Sheets(1).Range("A65536").End(xlUp).Row 
    iNbCellNoEmpty = 0
    
    For iLineRead = 1 To iNbLine
        If Trim(Sheets(1).Cells(iLineRead, 1)) <> "" Then
            iNbCellNoEmpty = iNbCellNoEmpty + 1
        End If
    Next iLineRead
    
    MsgBox "Nombre de cellule non vide = " & iNbCellNoEmpty
    0