Attribuer des opérateurs à des variables
Bonjour à tous,
Dans l'idée de réduire la taille d'une macro, je me suis dit qu'il pourrait etre judicieux dans mon cas d'atribuer à des variables la valeur "=" ou "<>" selon une condition. Malheureusement dans la ligne ou j'utilise ces variables, vba me sort une erreur "incompatibilité de type". J'ai bien essayé de déclarer les variables en string, variant, ou object, rien n'y fait... Si quelqu'un avait une petite solution à proposer
Voici mon code
Private Sub Creation_Click()
Dim annee As String
Dim up As String
Dim eq As String
Dim mois As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim i As String
If ComboBox1 = "" And ComboBox2 = "" And ComboBox3 = "" And ComboBox4 = "" Then
MsgBox " "
End If
If ComboBox1 <> "" Then
a = "="
Else
a = "<>"
End If
If ComboBox2 <> "" Then
b = "="
Else
b = "<>"
End If
If ComboBox3 <> "" Then
c = "="
Else
c = "<>"
End If
If ComboBox4 <> "" Then
d = "="
Else
d = "<>"
End If
For n = 2 To Sheets("data_1").Range("A100000").End(xlUp).Row
'Ligne qui utilise les variables en tort:
If CStr(Sheets("data_1").Range("E" & n)) & a & ComboBox1 And CStr(Sheets("data_1").Range("A" & n)) & b & ComboBox2 And CStr(Sheets("data_1").Range("B" & n)) & c & ComboBox3 And CStr(Sheets("data_1").Range("F" & n)) & d & ComboBox4 And CStr(Sheets("data_1").Range("K" & n)) <> "" Then
i = Sheets("data_1").Range("K" & n)
ActiveWorkbook.FollowHyperlink Address:=i
Else
MsgBox "Il n'y a pas de rapport enregistré pour ce contrôle"
End If
Next n
End Sub
Bonjour,
cette syntaxe n'est pas reconnue par vba
il y a une solution possible pour certains cas de figure avec application.evaluate
si cela peut t'inspirer
Sub test()
a = Cells(1, 1)
b = "="
c = "2"
s = a & b & c
If Application.Evaluate(s) Then
MsgBox "condition vraie pour s " & s
Else
MsgBox "condition fausse pour s " & s
End If
End Sub