OVH Cloud OVH Cloud

probleme avec findnext

2 réponses
Avatar
pierre
Bonjour,

voici les valeurs que j'ai dans une feuille excel.
a
b
c
a
b
a

je voudrais creer une fonction qui me retourne le nombre de "a" (ici 3)
voici mon code :

------------------------------------------------
Function test()
test = 0
With Worksheets(1).Range("a:a")
Set c = .Find("a", LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
test = test + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
End Function
------------------------------------------------

Le probleme est que findnext retourne toujours Nothing...
j'utilise excel xp avec windows 2000

Merci pour votre aide....
pierre

2 réponses

Avatar
...Patrick
Salut,

tu as vraiment besoin de réinventer la roue ?

un nb.si peut fonctionner

Bye

"pierre" a écrit dans le message de news:

Bonjour,

voici les valeurs que j'ai dans une feuille excel.
a
b
c
a
b
a

je voudrais creer une fonction qui me retourne le nombre de "a" (ici 3)
voici mon code :

------------------------------------------------
Function test()
test = 0
With Worksheets(1).Range("a:a")
Set c = .Find("a", LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
test = test + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
End Function
------------------------------------------------

Le probleme est que findnext retourne toujours Nothing...
j'utilise excel xp avec windows 2000

Merci pour votre aide....
pierre


Avatar
pierre
je voulais simplifier le code, il vrai que je l'ai peut etre trop simplifer...
mais en realité, voici ce que je veux faire :

----------------------------------------------
Function BUDGET(sheetname As String, account As Variant)
BUDGET = 0
With Worksheets(sheetname).Range("A:A")
Set c = .Find(What:¬count)
If Not c Is Nothing Then
firstAddress = c.Address
Do
BUDGET = BUDGET + Worksheets(sheetname).Cells(c.row,
2).Value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Function
----------------------------------------------

pierre



"...Patrick" wrote:

Salut,

tu as vraiment besoin de réinventer la roue ?

un nb.si peut fonctionner

Bye

"pierre" a écrit dans le message de news: