Concaténation de texte dans une variable

FloreR

XLDnaute Nouveau
Bonjour à tous,

J'ai créé deux macros :
- tout_en_un, sans arguments, qui fait elle-même appel à
- calcul_tout_en_un, qui possède 4 arguments de type string (règle, LCS, exclusions, limitation)

Lorsque je tests calcul_tout_en_un, par exemple via la macro ci-dessous, tout fonctionne.

Sub test()
Call calcul_tout_en_un("H14-CLP-A-H", "avec", "déchet", "oui")
End Sub

Par contre, lorsque j'essaye d'utiliser calcul_tout_en_un au sein de la macro tout_en_un, en définissant 4 variables pour mes arguments, qui prennent différentes valeurs au cours de la macro... ça ne marche plus !
Un message d'erreur apparaît au niveau de l'instruction suivante (le mot "règle" étant surligné) :

Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
=> "Erreur de compilation ; type d'argument ByRef incompatible."

Pourtant, j'ai bien déclaré mes 4 variables de type string au début de ma macro tout_en_un, et je leur ai attribué des valeurs qui collent avec ce qui est attendu...
Je me demande si ce n'est pas mon instruction pour définir la valeur de règle qui ne fonctionne pas :

règle = Sheets("Modalités de calcul").Cells(a + 10, 2).Text & "-" & Sheets("Modalités de calcul").Cells(a + 10, 3).Text & "-" & b_string & "-" & Sheets("Modalités de calcul").Cells(a + 10, 4).Text

(Le résultat doit être quelque chose comme "H14-CLP-A-H", b_string étant une autre variable string définie dans ma macro, qui vaut A, B, C, D, ..., et a étant une variable integer)

Voyez-vous quelque chose qui cloche dans mon attribution de valeur à la variable règle ?

Si jamais ce n'est pas ça le problème, vous trouverez ci-dessous le code complet.
Merci d'avance pour votre aide !!!


Sub toutenun()

Dim i, a, b, critère, nb_min_spéciés, nb_règles, nb_choix As Integer
Dim b_string, règle, LCS, exclusions, limitation As String

Sheets("Modalités de calcul").Activate
i = 11
While Cells(i, 2) <> ""
i = i + 1
Wend
nb_choix = i - 11

For a = 1 To nb_choix

nb_règles = Sheets("Modalités de calcul").Cells(a + 10, 12).Value
For b = 1 To nb_règles

If b = 1 Then
b_string = "A"
End If
If b = 2 Then
b_string = "B"
End If
If b = 3 Then
b_string = "C"
End If
If b = 4 Then
b_string = "D"
End If

règle = Sheets("Modalités de calcul").Cells(a + 10, 2).Text & "-" & Sheets("Modalités de calcul").Cells(a + 10, 3).Text & "-" & b_string & "-" & Sheets("Modalités de calcul").Cells(a + 10, 4).Text


If Cells(a + 10, 5) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "avec"
exclusions = "aucune"
limitation = "oui"
Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 5) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "avec"
exclusions = "aucune"
limitation = "non"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 5) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "sans"
exclusions = "aucune"
limitation = "oui"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 5) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "sans"
exclusions = "aucune"
limitation = "non"
'excel.Run(calcul_tout_en_un, règle, LCS, exclusions, limitation)

End If

If Cells(a + 10, 6) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "avec"
exclusions = "déchet"
limitation = "oui"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 6) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "avec"
exclusions = "déchet"
limitation = "non"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 6) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "sans"
exclusions = "déchet"
limitation = "oui"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 6) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "sans"
exclusions = "déchet"
limitation = "non"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 7) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "avec"
exclusions = "tous_rares"
limitation = "oui"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 7) <> "" And Cells(a + 10, 8) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "avec"
exclusions = "tous_rares"
limitation = "non"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 7) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 10) <> "" Then
LCS = "sans"
exclusions = "tous_rares"
limitation = "oui"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If

If Cells(a + 10, 7) <> "" And Cells(a + 10, 9) <> "" And Cells(a + 10, 11) <> "" Then
LCS = "sans"
exclusions = "tous_rares"
limitation = "non"
'Call calcul_tout_en_un(règle, LCS, exclusions, limitation)
End If


Next b
Next a


Flag_Droit_Modif = False

End Sub



Public Sub calcul_tout_en_un(règle As String, LCS As String, exclusions As String, limitation As String)

Dim i, j As Integer

Sheets("Résultats généraux").Activate
j = 1
While Cells(j, 1) <> ""
j = j + 1
Wend


Call clic_tri_dans_selection(règle, LCS, exclusions, limitation)
recopiagedonnéesdéchetdanssélection
Call préselection(règle, LCS, exclusions, limitation)
extraction
Clic_spéciation
Call Clic_exporterésultats(règle, LCS, exclusions, limitation)

i = 15
While Cells(i, 2) <> ""
i = i + 1
Wend
nb_min_spéciés = i - 15

Sheets("Résultats généraux").Select
i = j

If Sheets("Feuille de résultats").Cells(14 + nb_min_spéciés + 5, 1) <> "Aucun" Then
While Sheets("Feuille de résultats").Cells(14 + nb_min_spéciés + 5 - j + i, 1) <> ""
Sheets("Résultats généraux").Cells(i, 12) = Sheets("Feuille de résultats").Cells(14 + nb_min_spéciés + 5 - j + i, 1)
Sheets("Résultats généraux").Cells(i, 13) = Sheets("Feuille de résultats").Cells(14 + nb_min_spéciés + 5 - j + i, 2)
i = i + 1
Wend
End If


i = j

While i < j + nb_min_spéciés
Cells(i, 1) = Sheets("Déchet").Cells(2, 3)
Cells(i, 2) = règle
' Sheets("Sélection").Cells(5, 5) + signification
Cells(i, 3) = exclusions
Cells(i, 4) = LCS
'Sheets("Sélection").Cells(7, 5)
Cells(i, 5) = limitation
'Sheets("Déchet").Cells(4, 3)
Cells(i, 7) = Sheets("Feuille de résultats").Cells(15 + i - j, 1)
Cells(i, 8) = Sheets("Feuille de résultats").Cells(15 + i - j, 2)
Cells(i, 9) = Sheets("Feuille de résultats").Cells(15 + i - j, 3)
Cells(i, 10) = Sheets("Feuille de résultats").Cells(15 + i - j, 4)

i = i + 1
Wend


End Sub
 

pierrejean

XLDnaute Barbatruc
Re : Concaténation de texte dans une variable

Bonjour FLORER

Je n'ai pas tout étudié mais ...
Lorsque tu ecris

Dim b_string, règle, LCS, exclusions, limitation As String

Règle n'est pas defini comme String mais comme Variant
teste:
Dim b_string, règle as String, LCS, exclusions, limitation As String
 

tbft

XLDnaute Accro
Re : Concaténation de texte dans une variable

bonjour

juste au passage, on peut ecrire
Clic_exporterésultats règle, LCS, exclusions, limitation

au lieu d'écrire
Call Clic_exporterésultats(règle, LCS, exclusions, limitation)
 

Discussions similaires

Statistiques des forums

Discussions
312 232
Messages
2 086 461
Membres
103 219
dernier inscrit
Akyrah