Formule si/et/ou en VBA

Bonjour,

Je ne comprends pas pourquoi ma formule ne fonctionne pas en VBA :

Sub SuiteMACROSIAFinal()

'PAS DE DECOMPTE OU DECOMPTE A EMETTRE(6)

'(Autre formule sans enregistrement mais fonctionne pas(6))

If .Cells(j,"N")= "" And Cells(j, "Q") = "" And Cells(j, "R") < 15000 And Cells(j, "H").Value = "002160" Or Cells(j, "H").Value = "001170" Or Cells(j, "H").Value = "001121") Then

.Cells(j, "M") = "PAS DE DECOMPTE"

Else: .Cells(j, "M") = "DECOMPTE A EMETTRE"

End If

End With

Next j

End Sub

Pour que vous comprenez mieux la formule, il s'agit de la suivante que je voudrais coder en VBA (et non faire copier-coller de la fourmule ci-dessous dans VBA) :

=SI(ET(N7="";Q7="";OU(H7="001121";H7="001170";H7="002160");ABS(R7)<15000);"PAS DE DECOMPTE";"DECOMPTE A EMETTRE")

Merci !!

Bonjour,

Il manque des parenthèses, tente avec :

If .Cells(j,"N")= "" And Cells(j, "Q") = "" And Abs(Cells(j, "R") < 15000) And (Cells(j, "H").Value = "002160" Or Cells(j, "H").Value = "001170" Or Cells(j, "H").Value = "001121")

Merci pour ta réponse mais il ne se passe toujours rien et aucun message d’erreur s'affiche ...

Voici le code après modification :

Sub MACROFinal ()

With Sheets("SUIVTRANS EN COURS")

For j = 2 To Derligne

If .Cells(j, "N") = "" And Cells(j, "Q") = "" And Abs(Cells(j, "R") < 15000) And (Cells(j, "H").Value = "002160" Or Cells(j, "H").Value = "001170" Or Cells(j, "H").Value = "001121") Then

Cells(j, "M") = "PAS DE DECOMPTE"

Else: Cells(j, "M") = "DECOMPTE A EMETTRE"

End If

Next j

End With

End Sub

Merci de ton aide c'est vraiment très important :/

Question bête, mais il y a quoi comme valeur dans ta variable derligne ?

Etant donné qu'entre "Sub MACROFinal ()" et "End Sub" je ne vois aucune instruction qui y fait référence...

Voici ma variable

Derligne = .Range("A" & Rows.Count).End(xlUp).Row

Mais le problème c'est cette ligne qui fonctionne pas :

If .Cells(j, "N") = "" And Cells(j, "Q") = "" And Abs(Cells(j, "R") < 15000) And (Cells(j, "H").Value = "002160" Or Cells(j, "H").Value = "001170" Or Cells(j, "H").Value = "001121") Then

Cells(j, "M") = "PAS DE DECOMPTE"

Else: Cells(j, "M") = "DECOMPTE A EMETTRE"

Fais une exécution pas à pas avec F8 et passe ta souris sur les différentes instructions pour voir quelles valeurs sont renvoyées.

Bonjour KOBD, Pedro22, le forum,

Un essai.....

Sub MACROFinal()

Dim Derligne As Integer
    Derligne = Range("A" & Rows.Count).End(xlUp).Row

  With Sheets("SUIVTRANS EN COURS")
   For j = 2 To Derligne

       Range("M" & j).ClearContents

    Select Case conditions
     Case Cells(j, "N") = "" And Cells(j, "Q") = "" And Cells(j, "R") <> "", Cells(j, "R") < 15000, Cells(j, "H").Value = 1121 Or Cells(j, "H").Value = 1170 Or Cells(j, "H").Value = 2160
          Cells(j, "M") = "DECOMPTE A EMETTRE"
     Case Else
          Cells(j, "M") = "PAS DE DECOMPTE"
     End Select
   Next j
  End With
End Sub
10kobd.xlsm (18.70 Ko)

Cordialement,

Rechercher des sujets similaires à "formule vba"