Désolé, j'ai pas tout compris ...
Heuu .... merci ouskel'n'or :lol:
Mais voilà j'ai :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 'Extraction de la chaine de caractère jusqu'au ";" ---------------------------------------------------
Dim strOldChar As String
Dim intPosition As Integer
intPosition = InStr(1, strValue, ";") - 1
strOldChar = Left(strValue, intPosition)
'Vérification que la chaine avant le ";" existe bien dans la feuille Excel "WorkFiles" ----------------
Dim boolStringFind As Boolean
With Worksheets("Work files").Range("C:C")
Set boolStringFind = .Find(strOldChar, LookIn:=xlValues)
boolStringFind = Not boolStringFind Is Nothing
Set boolStringFind = Nothing
End With
If boolStringFind = Nothing Then
MsgBox "Your request value ( " & strOldChar & " ) does not exist in all filename !", vbCritical, "!STOP!"
boolvalidity = False
Else
boolvalidity = True
End If |
ça ne fonctionne pas qu'est-ce que j'oublie ?
ouskel'n'or j' ta'dor ;-)
Super merci, ça fonctionne, bon j'ai moi aussi corrigé un peu le code car j'avais fait une erreur sur le type boolStringFing qui n'est pas un boolean mais un objet d'où le nouveau nom objStringFind ;)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| 'Vérification que la chaine avant le ";" existe bien dans la feuille Excel "WorkFiles" ----------------
Dim objStringFind
Dim ok As Boolean
Sheets("Work files").Activate
With Worksheets("Work files").Range("C:C")
Set objStringFind = .Find(strOldChar, LookIn:=xlValues)
If Not objStringFind Is Nothing Then ok = True
Set objStringFind = Nothing
End With
If Not ok Then
MsgBox "Your request value ( " & strOldChar & " ) does not exist in all filename !", vbCritical, "!STOP!"
boolvalidity = False
Else
boolvalidity = True
End If
Sheets("Reference File GENERATOR").Activate |
Il ne reste plus qu'à vérifier que si le premier caractère après le ";" est une lettre, je regarde qu'il corresponde bien à un avion. :pc:
Puis, je passerais le code complet pour info.
@ plus.
Merci encore
Paloma
:merci:
Voilà j'ai presque fini ...
Bon d'accord j'ai encore un truc qui ne fonctionne pas bien.
Donc dans mon code, il y a trois vérifications sur la saisie :
Code:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| Private Sub ButAdd_Click()
strValue = InputBox("Please enter a value to consider to translate the package", "Add filter")
If strValue = "NULL" Or strValue = "" Then
MsgBox "You must enter a not empty value!", vbCritical, "!STOP!"
Exit Sub
Else
'=(1)==================================================================================================================
'vérification que le séparateur ";" existe -------------------------------------------------------------
If InStr(1, strValue, ";") = 0 Then
boolvalidity = False
MsgBox "You forget ; char separator between old value and new value!", vbCritical, "!STOP!"
Exit Sub
Else
boolvalidity = True
End If
'Extraction de la chaine de caractère jusqu'au ";" ---------------------------------------------------
Dim strOldChar As String
Dim intPosition As Integer
intPosition = InStr(1, strValue, ";") - 1
strOldChar = Left(strValue, intPosition)
'=(2)==================================================================================================================
'Vérification que la chaine avant le ";" existe bien dans la feuille Excel "WorkFiles" ----------------
Dim objStringFind
Dim ok As Boolean
'Sheets("Work files").Activate
With Worksheets("Work files").Range("C:C")
Set objStringFind = .Find(strOldChar, LookIn:=xlValues)
If Not objStringFind Is Nothing Then ok = True
Set objStringFind = Nothing
End With
If Not ok Then
MsgBox "Your request value ( " & strOldChar & " ) does not exist in all filename !", vbCritical, "!STOP!"
boolvalidity = False
Else
boolvalidity = True
End If
'Sheets("Reference File GENERATOR").Activate
'=(3)==================================================================================================================
'Extraction du premier caractère après le ";" ----------------------------------------------------------
Dim strAircraftChar As String
'Dim intPosition As Integer
intPosition = InStr(1, strValue, ";") + 1
strAircraftChar = Mid(strValue, intPosition, 1)
'Vérification que ce caractère est bien une Lettre de l'alphabet ---------------------------------------
Dim intCODE As Integer
intCODE = Asc(strAircraftChar)
If intCODE < 65 Then
Else
'Vérification Programme Avion (AIRBUS) -----------------------------------------------------------------
'strSingleValue = strValue
Call chkPrograms(strAircraftChar)
End If
'Ajout du filtre si toutes les condition sont vrai ----------------------------------------------------------
If boolvalidity = True Then
ListBoxFilters.AddItem UCase(strValue)
ButGenerate.Visible = True
Else
MsgBox "For to add a new filter, please you must enter a value corresponding to a part of the old file name then a (;) separator and after a value to change the first value you has entered", vbInformation, "Tips for added a new filter :"
End If
End If
End Sub |
a partir du :
'=(3)==================================================================================================================
Le problème c'est que, si j'ai bien une lettre après le ";" la fonction chkPrograms est appelée mais elle ne fonctionne pas.
Code:
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 41
| Public Function chkPrograms(strSingleValue As String) As String
'Programs Descriptions ---------------------------------------------
Dim DataString(10) As String
Dim InString() As String
Dim i As Integer
Dim strActive As String
'Remplissage du tableau qui va être testé
DataString(0) = "R" ' AC_WBY_A300
DataString(1) = "L" ' AC_SA_A318
DataString(2) = "L" ' AC_SA_A319
DataString(3) = "L" ' AC_SA_A319CJ
DataString(4) = "L" ' AC_SA_A320
DataString(5) = "L" 'AC_SA_A321
DataString(6) = "N" ' AC_LR_A330
DataString(7) = "N" ' AC_LR_A340
DataString(8) = "F" ' AC_LR_A380
DataString(9) = "N" ' AC_XWB_A350
DataString(10) = "M" ' AC_Military_A400M
'"DataString" est le tableau dans lequel doit être effectué la recherche.
'"str" est la chaîne à rechercher.
'La fonction Filter renvoie le tableau "InString" contenant les éléments
'qui répondent aux critères de la recherche.
InString = Filter(DataString, strSingleValue, True, vbTextCompare)
strActive = DataString(i)
'Boucle sur le tableau afin de visualiser les éléments
'qui répondent aux critères de recherche.
For i = 0 To UBound(InString)
Debug.Print InString(i)
Next i
If strSingleValue = strActive Then
Else
MsgBox "You enter an invalid Aircraft Programs Letter (" & strActive & ")", vbCritical, "Airbus Policy"
End If
End Function |
Je cherche si la lettre trouvée est bien dans le tableau si ok je ne fais rien, sinon, j'affiche un message d'erreur avec le caractère en question, j'informe que ce n'est pas un caractère valide et je passe ma valeur boolvalidity à false dans la partie principale du programme.
Si quelqu'un peu m'aider à ce sujet.
Bien à vous.
Paloma