Bonjour,
Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un
module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le
module "Test"
Je vous remercie
Alain
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
FS
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la fonction Split intégrée) ? Mais, donc, testé avec Excel 97 :
'======================== Sub NbOccur() Dim S As String With ThisWorkbook.VBProject.VBComponents("Test").CodeModule S = .Lines(1, .CountOfLines) End With MsgBox SplitFor97("Alpha", S).Count - 1 End Sub
Function SplitFor97(split_string As String, orig_string As String) As Collection
If split_string = "" Then Exit Function Dim Coll As New Collection
Dim pos pos = 1 Dim token As String Dim my_string As String my_string = orig_string
While my_string <> "" And pos <> 0 pos = InStr(1, my_string, split_string) If pos > 0 Then token = Left(my_string, pos - 1) If token <> "" Then Coll.Add token my_string = Mid(my_string, pos + Len(split_string)) End If Wend If my_string <> "" Then Coll.Add my_string Set SplitFor97 = Coll End Function '======================== FS -- Frédéric SIGONNEAU Modules et modèles pour Excel : http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour, Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le module "Test" Je vous remercie Alain
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la
fonction Split intégrée) ?
Mais, donc, testé avec Excel 97 :
'======================== Sub NbOccur()
Dim S As String
With ThisWorkbook.VBProject.VBComponents("Test").CodeModule
S = .Lines(1, .CountOfLines)
End With
MsgBox SplitFor97("Alpha", S).Count - 1
End Sub
Function SplitFor97(split_string As String, orig_string As String) As
Collection
If split_string = "" Then Exit Function
Dim Coll As New Collection
Dim pos
pos = 1
Dim token As String
Dim my_string As String
my_string = orig_string
While my_string <> "" And pos <> 0
pos = InStr(1, my_string, split_string)
If pos > 0 Then
token = Left(my_string, pos - 1)
If token <> "" Then Coll.Add token
my_string = Mid(my_string, pos + Len(split_string))
End If
Wend
If my_string <> "" Then Coll.Add my_string
Set SplitFor97 = Coll
End Function
'========================
FS
--
Frédéric SIGONNEAU
Modules et modèles pour Excel :
http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour,
Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un
module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le
module "Test"
Je vous remercie
Alain
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la fonction Split intégrée) ? Mais, donc, testé avec Excel 97 :
'======================== Sub NbOccur() Dim S As String With ThisWorkbook.VBProject.VBComponents("Test").CodeModule S = .Lines(1, .CountOfLines) End With MsgBox SplitFor97("Alpha", S).Count - 1 End Sub
Function SplitFor97(split_string As String, orig_string As String) As Collection
If split_string = "" Then Exit Function Dim Coll As New Collection
Dim pos pos = 1 Dim token As String Dim my_string As String my_string = orig_string
While my_string <> "" And pos <> 0 pos = InStr(1, my_string, split_string) If pos > 0 Then token = Left(my_string, pos - 1) If token <> "" Then Coll.Add token my_string = Mid(my_string, pos + Len(split_string)) End If Wend If my_string <> "" Then Coll.Add my_string Set SplitFor97 = Coll End Function '======================== FS -- Frédéric SIGONNEAU Modules et modèles pour Excel : http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour, Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le module "Test" Je vous remercie Alain
alain Lebayle
Encore une fois un très très grand merci... C'est parfait ! Alain
"FS" a écrit dans le message de news: eMnBVS%
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la fonction Split intégrée) ? Mais, donc, testé avec Excel 97 :
'======================== > Sub NbOccur() Dim S As String With ThisWorkbook.VBProject.VBComponents("Test").CodeModule S = .Lines(1, .CountOfLines) End With MsgBox SplitFor97("Alpha", S).Count - 1 End Sub
Function SplitFor97(split_string As String, orig_string As String) As Collection
If split_string = "" Then Exit Function Dim Coll As New Collection
Dim pos pos = 1 Dim token As String Dim my_string As String my_string = orig_string
While my_string <> "" And pos <> 0 pos = InStr(1, my_string, split_string) If pos > 0 Then token = Left(my_string, pos - 1) If token <> "" Then Coll.Add token my_string = Mid(my_string, pos + Len(split_string)) End If Wend If my_string <> "" Then Coll.Add my_string Set SplitFor97 = Coll End Function '======================== > FS -- Frédéric SIGONNEAU Modules et modèles pour Excel : http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour, Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le module "Test" Je vous remercie Alain
Encore une fois un très très grand merci...
C'est parfait !
Alain
"FS" <fs@news.group> a écrit dans le message de news:
eMnBVS%23UKHA.1236@TK2MSFTNGP05.phx.gbl...
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la
fonction Split intégrée) ?
Mais, donc, testé avec Excel 97 :
'======================== > Sub NbOccur()
Dim S As String
With ThisWorkbook.VBProject.VBComponents("Test").CodeModule
S = .Lines(1, .CountOfLines)
End With
MsgBox SplitFor97("Alpha", S).Count - 1
End Sub
Function SplitFor97(split_string As String, orig_string As String) As
Collection
If split_string = "" Then Exit Function
Dim Coll As New Collection
Dim pos
pos = 1
Dim token As String
Dim my_string As String
my_string = orig_string
While my_string <> "" And pos <> 0
pos = InStr(1, my_string, split_string)
If pos > 0 Then
token = Left(my_string, pos - 1)
If token <> "" Then Coll.Add token
my_string = Mid(my_string, pos + Len(split_string))
End If
Wend
If my_string <> "" Then Coll.Add my_string
Set SplitFor97 = Coll
End Function
'======================== >
FS
--
Frédéric SIGONNEAU
Modules et modèles pour Excel :
http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour,
Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un
module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le
module "Test"
Je vous remercie
Alain
Encore une fois un très très grand merci... C'est parfait ! Alain
"FS" a écrit dans le message de news: eMnBVS%
Toujours pour Excel 97, je suppose (sinon, c'est plus simple avec la fonction Split intégrée) ? Mais, donc, testé avec Excel 97 :
'======================== > Sub NbOccur() Dim S As String With ThisWorkbook.VBProject.VBComponents("Test").CodeModule S = .Lines(1, .CountOfLines) End With MsgBox SplitFor97("Alpha", S).Count - 1 End Sub
Function SplitFor97(split_string As String, orig_string As String) As Collection
If split_string = "" Then Exit Function Dim Coll As New Collection
Dim pos pos = 1 Dim token As String Dim my_string As String my_string = orig_string
While my_string <> "" And pos <> 0 pos = InStr(1, my_string, split_string) If pos > 0 Then token = Left(my_string, pos - 1) If token <> "" Then Coll.Add token my_string = Mid(my_string, pos + Len(split_string)) End If Wend If my_string <> "" Then Coll.Add my_string Set SplitFor97 = Coll End Function '======================== > FS -- Frédéric SIGONNEAU Modules et modèles pour Excel : http://frederic.sigonneau.free.fr/
alain Lebayle a écrit :
Bonjour, Dans un msgbox, je souhaite connaître le nombre d'une occurrence dans un module. Par exemple le nombre de fois qu'apparaît le mo "Alpha" dans le module "Test" Je vous remercie Alain