OVH Cloud OVH Cloud

traduire SI(OU(GAUCHE(AB55),1);... en VBA

6 réponses
Avatar
Nicoh
Bonjour à tous,

Je souhaiterais obtenir en VBA la formule suivante :
SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
dans le code suivant :

If Not Intersect(Target, [AB55]) Is Nothing Then
If Left([AB55], 1) = "L" Then
question = MsgBox("Est-ce un dito ?", vbYesNo, Application.UserName)
If question = vbYes Then
[ab56] = "DITO 2006"
[ab56].Select
End If
End If
End If

Par avance merci, j'ai essayé des tas de formules en vain

Nicoh

6 réponses

Avatar
anonymousA
Bonjour,

if left(cells(55,27).value,1)="L" or left(cells(55,27).value,2)="IL" then

'et ainsi de suite

A+

Bonjour à tous,

Je souhaiterais obtenir en VBA la formule suivante :
SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
dans le code suivant :

If Not Intersect(Target, [AB55]) Is Nothing Then
If Left([AB55], 1) = "L" Then
question = MsgBox("Est-ce un dito ?", vbYesNo, Application.UserName)
If question = vbYes Then
[ab56] = "DITO 2006"
[ab56].Select
End If
End If
End If

Par avance merci, j'ai essayé des tas de formules en vain

Nicoh


Avatar
Jacky
Bonjour,

SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
en VBA:

If Left([AB55], 1) = "L" Or Left([AB55], 2) = "IL" Then

--
Salutations
JJ


"Nicoh" a écrit dans le message de news:

Bonjour à tous,

Je souhaiterais obtenir en VBA la formule suivante :
SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
dans le code suivant :

If Not Intersect(Target, [AB55]) Is Nothing Then
If Left([AB55], 1) = "L" Then
question = MsgBox("Est-ce un dito ?", vbYesNo, Application.UserName)
If question = vbYes Then
[ab56] = "DITO 2006"
[ab56].Select
End If
End If
End If

Par avance merci, j'ai essayé des tas de formules en vain

Nicoh


Avatar
Nicoh
Bonjour Jacky,

Merci pour ta réponse qui me convient parfaitement.
Par contre, j'ai personnalisé le code que tu m'as construit il y a quelques
jours et j'arrive au résultat suivant :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, [BA6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
[BA5] = "NEW"
[BC6].Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If
If Not Intersect(Target, [BC6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
[BC5] = "NEW"
[BE6].Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If

tu as sûrement constaté que j'ai recopié deux fois le code pour que la macro
s'éxécute en BA6 puis en BC6. Est-il possible d'éviter de recopier ? En
effet, la formule doit s'appliquer sur 14 cellules. J'ai essayé ce qui suit,
mais j'obtiens NEW sur toute la plage :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range (BA6,BC6) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
Range(BA5,BC5) = "NEW"
Range(BC6,BE6).Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If

Merci par avance pour ton aide précieuse.

Nicoh

Bonjour,

SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
en VBA:

If Left([AB55], 1) = "L" Or Left([AB55], 2) = "IL" Then

--
Salutations




Avatar
Jacky
Re...
La macro de départ a été entièrement modifiées, et n'a plus rien à voir avec
la demande initiale :-(

Donne la plage des cellules à vérifier et le contrôle souhaité, clairement
et complètement.
ou alors
If Not Intersect(Target, Range (BA6,BC6)
le range doit comporter les cellules à vérifier entre guillemet

Range ("ba6,bc6,xxx,yyy,zzz,etc")

--
Salutations
JJ


"Nicoh" a écrit dans le message de news:

Bonjour Jacky,

Merci pour ta réponse qui me convient parfaitement.
Par contre, j'ai personnalisé le code que tu m'as construit il y a
quelques
jours et j'arrive au résultat suivant :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, [BA6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
[BA5] = "NEW"
[BC6].Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If
If Not Intersect(Target, [BC6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
[BC5] = "NEW"
[BE6].Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If

tu as sûrement constaté que j'ai recopié deux fois le code pour que la
macro
s'éxécute en BA6 puis en BC6. Est-il possible d'éviter de recopier ? En
effet, la formule doit s'appliquer sur 14 cellules. J'ai essayé ce qui
suit,
mais j'obtiens NEW sur toute la plage :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range (BA6,BC6) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbYes Then
Range(BA5,BC5) = "NEW"
Range(BC6,BE6).Select
Else
If question = vbNo Then
question = MsgBox("Le texte est-il identique ?", 4, Application.UserName)
If question = 7 Then [AW8].Select: Exit Sub
End If
End If
End If

Merci par avance pour ton aide précieuse.

Nicoh

Bonjour,

SI(OU(GAUCHE(AB55,1)="L";GAUCHE(AB55,2)="IL"...
en VBA:

If Left([AB55], 1) = "L" Or Left([AB55], 2) = "IL" Then

--
Salutations






Avatar
Nicoh
Re ...

Maintenant que j'arrive à peu près à comprendre le fonctionnement des
macros, j'essai des choses tout seul comme un grand. J'ai donc effectivement
fait évoluer la macro initiale.
Je suis arrivé au résultat que je souhaitais, mais le code est très long. La
macro est donc maintenant celle-ci :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, [BA6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbNo Then
question = MsgBox("Le texte est-il DITO ?", 4,
Application.UserName)
If question = 7 Then
[AW8].Select
End If
Else
If question = vbYes Then
question = MsgBox("La facturation se fait-elle sur 12 mois ?",
4, Application.UserName)
If question = 7 Then
[BA5] = "NEW"
[AW8].Select: Exit Sub
End If
End If
End If
End If
If Not Intersect(Target, [BC6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbNo Then
question = MsgBox("Le texte est-il DITO ?", 4,
Application.UserName)
If question = 7 Then
[AW8].Select
End If
Else
If question = vbYes Then
question = MsgBox("La facturation se fait-elle sur 12 mois ?",
4, Application.UserName)
If question = 7 Then
[BC5] = "NEW"
[AW8].Select: Exit Sub
End If
End If
End If
End If

Ainsi de suite jusque CC6 (et donc CC5)

Pour répondre à ta question, la plage est donc BA6:CC6, sachant que les
cellules sont fusionnées deux par deux, et BA5 par BC5 jusque CC5.
Tout le reste est inchangé càd AW8 est invariable.

Merci beaucoup pour ton aide
Avatar
Jacky
Re...
sachant que les cellules sont fusionnées deux par deux, et BA5 par BC5
jusque CC5.
???????

Je suis pas très sur d'avoir compris
Teste ceci:
'------------
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("ba6:cc6")) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", 4, Application.UserName)
If question = 7 Then
question = MsgBox("Le texte est-il DITO ?", 4, Application.UserName)
If question = 7 Then
[AW8].Select
Exit Sub
End If
Else
'If question = vbYes Then
question = MsgBox("La facturation se fait-elle sur 12 mois ?",
4, Application.UserName)
If question = 7 Then
Cells(Target.Row - 1, Target.Column) = "NEW"
[AW8].Select
End If
' End If
End If
End If
End Sub
'---------------
--
Salutations
JJ



"Nicoh" a écrit dans le message de news:

Re ...

Maintenant que j'arrive à peu près à comprendre le fonctionnement des
macros, j'essai des choses tout seul comme un grand. J'ai donc
effectivement
fait évoluer la macro initiale.
Je suis arrivé au résultat que je souhaitais, mais le code est très long.
La
macro est donc maintenant celle-ci :

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, [BA6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbNo Then
question = MsgBox("Le texte est-il DITO ?", 4,
Application.UserName)
If question = 7 Then
[AW8].Select
End If
Else
If question = vbYes Then
question = MsgBox("La facturation se fait-elle sur 12 mois ?",
4, Application.UserName)
If question = 7 Then
[BA5] = "NEW"
[AW8].Select: Exit Sub
End If
End If
End If
End If
If Not Intersect(Target, [BC6]) Is Nothing Then
question = MsgBox("Est-ce un NEW ?", vbYesNo, Application.UserName)
If question = vbNo Then
question = MsgBox("Le texte est-il DITO ?", 4,
Application.UserName)
If question = 7 Then
[AW8].Select
End If
Else
If question = vbYes Then
question = MsgBox("La facturation se fait-elle sur 12 mois ?",
4, Application.UserName)
If question = 7 Then
[BC5] = "NEW"
[AW8].Select: Exit Sub
End If
End If
End If
End If

Ainsi de suite jusque CC6 (et donc CC5)

Pour répondre à ta question, la plage est donc BA6:CC6, sachant que les
cellules sont fusionnées deux par deux, et BA5 par BC5 jusque CC5.
Tout le reste est inchangé càd AW8 est invariable.

Merci beaucoup pour ton aide