Problème de boucle avec for
Résolu
davsnoop
-
ShaBoo Messages postés 406 Statut Membre -
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
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
A voir également:
- Problème de boucle avec for
- Downloader for pc - Télécharger - Téléchargement & Transfert
- Idm for mac - Télécharger - Téléchargement & Transfert
- Instagram for pc - Télécharger - Divers Communication
- Microsoft store download for pc - Guide
- Winrar for pc - Télécharger - Compression & Décompression
2 réponses
Bonjour,
tu peux essayer ceci :
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
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