1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Sub test()
Dim x$, c1 As Range, c2 As Range, nums As Variant, serie As Variant
x = InputBox("entrez un/deux numeros")
If x <> vbNullString Then ' si on annule pas et que la chaine tapée correspond a un chiffre + "/" + un chiffre
With Sheets(1).Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
'on met tout en bleu au depart
.Parent.Range(.Cells(1, 1), .Cells(.Cells.Count)).Interior.Color = RGB(0, 150, 255)
serie = Split(x, ",")
For s = 0 To UBound(serie)
If Not serie(s) Like "*/*" Then serie(s) = serie(s) & "/" & serie(s)
If IsNumeric(Replace(serie(s), "/", "")) And serie(s) Like "*#/#*" Then
nums = Split(serie(s), "/")
'on cherche le 1°chiffre nom-+ nums(0)
Set c1 = .Find("nom-" & nums(0), lookat:=xlWhole)
'on cherche le 2d chiffre nom-+ nums(1)
Set c2 = .Find("nom-" & nums(1), lookat:=xlWhole)
critere = Not c1 Is Nothing And Not c2 Is Nothing
'si c1 n'est pas rien
If critere Then .Parent.Range(c1, c2).Interior.Color = RGB(255, 200, 50) Else mess = mess & "la plage contenant ""nom-" & nums(0) & """ & ""nom-" & nums(1) & """ n'existe pas !!" & vbCrLf
ElseIf Not IsNumeric(Replace(serie(s), "/", "")) And serie(s) Like "*/*" Then
'on cherche le 1er nom
Nom = Split(x, "/")
For j = 0 To UBound(Nom)
If j = 0 Then y = Nom(j)
If j = 1 Then Z = Nom(j)
Next
Set c1 = .Find(y & "*~", lookat:=xlWhole)
'on cherche le 2d chiffre nom-+ nums(1)
Set c2 = .Find(Z & "*~", lookat:=xlWhole)
critere = Not c1 Is Nothing And Not c2 Is Nothing
'si c1 n'est pas rien
If critere Then .Parent.Range(c1, c2).Interior.Color = RGB(255, 200, 50) Else mess = mess & "la plage contenant x & ""nom-" & nums(1) & """ n'existe pas !!" & vbCrLf
End If
Next
If mess <> "" Then MsgBox mess
End With
Else
MsgBox "vous avez annulé"
End If
End Sub |
Partager