1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| ' Compter le nombre de dirigeants
Sub Compte()
' variables
Dim plageSource As String
Dim nomPlageSource As String
Dim plageCible As String
Dim nomPlageCible As String
Dim rng As Range
Dim rngColonne As Range
Dim rng2 As Range
Dim cellule As Range
Dim c As Integer
Dim i As Integer
' Saisie des données
plageSource = "ListeBruteDesDirigeants"
nomPlageSource = "C1:C3"
' Corps
Set rng = ThisWorkbook.Worksheets(plageSource).Range(nomPlageSource).CurrentRegion
Set rngColonne = rng.Columns.Item(3)
' Debug
MsgBox (rngColonne.Rows.Count)
MsgBox (rngColonne.Columns.Count)
' On redimensionne
Set rng2 = rngColonne.Resize(rngColonne.Rows.Count, 1)
' Debug
MsgBox ("row=" & rng2.Rows.Count)
MsgBox ("col=" & rng2.Columns.Count)
MsgBox (rng2.Address)
' On parcourt la colonne
For Each cellule In rng2
c = 0
' Debug
MsgBox ("add = " & cellule.Address)
' Malheur, je me rend compte que l'objet est toujours la colonne et n'est pas la cellule, contrairement à ce que je pense.
' Problème de typage, car une colonne n'a pas de valeur.
For i = 1 To Len(cellule.Value)
' Debug
' MsgBox (VarType(cellule.Value))
If (Mid(cellule.Value, i, 1) = "$") Then
c = c + 1
End If
Next
' Debug
MsgBox (cellule.Address)
Cells(cellule.Row, cellule.Column + 1).Value = c
Next cellule
End Sub |
Partager