variable dans une macro

L

lesuisse

Guest
Bonjour à toutes et à tous...

Ca fait plaisir de revenir sur le forum après plus de 6 mois d'absence.

J'ai un petit souci avec le code suivant:

Dim f As String

f = Range("K7").Value

Dim cell As Range
For Each cell In Sheets("Overdue").Range("R2:R65536")
If Not IsEmpty(cell) Then
If cell > f Then
cell.Interior.ColorIndex = 8
End If
End If
Next cell

Je souhaiterai mettre le ">" en tant que variable.
C'est a dire que l'utilisateur pourra dans une cellule (M7 exactement) entrer soit: =, >, >= etc...
Donc comment variabiliser le signe permettant le tri ?

Merci à toutes et à tous pour votre aide.

Le suisse
 
Y

yeahou

Guest
Bonjour Lesuisse, le forum

ce petit code fonctionne, j'ai modifié le type de f car je pense que tu essayes de comparer des chiffres.

Cordialement, A+

Dim f As Long

f = Range("K7").Value

Dim Cell As Range
For Each Cell In Sheets("Overdue").Range("R2:R65536")
If Not (IsEmpty(Cell)) Then
Select Case Range("M7")
Case Is = ">"
If Cell.Value > f Then
Cell.Interior.ColorIndex = 8
Else
Cell.Interior.ColorIndex = xlNone
End If
Case Is = ">="
If Cell.Value >= f Then
Cell.Interior.ColorIndex = 8
Else
Cell.Interior.ColorIndex = xlNone
End If
Case Is = "<"
If Cell.Value < f Then
Cell.Interior.ColorIndex = 8
Else
Cell.Interior.ColorIndex = xlNone
End If
Case Is = "<="
If Cell.Value <= f Then
Cell.Interior.ColorIndex = 8
Else
Cell.Interior.ColorIndex = xlNone
End If
Case Is = "="
If Cell.Value = f Then
Cell.Interior.ColorIndex = 8
Else
Cell.Interior.ColorIndex = xlNone
End If
Case Else
End Select
End If
Next Cell
 

Discussions similaires

Réponses
21
Affichages
293
Réponses
1
Affichages
168
Réponses
0
Affichages
153

Statistiques des forums

Discussions
312 231
Messages
2 086 447
Membres
103 213
dernier inscrit
Poupoule