Macro avec plusieurs conditions
n
Bonjour à tous,
J'ai un problème concernant un macro que j’essaie de réaliser. voici le code que j'ai écrit mais y'a pas mal d'erreur apparemment vu que je viens de débuter en macro.
Sub Macro1()
Dim cel As Range
Dim plage As Range
Dim plage1 As Range
With Sheets("Sheet1")
Set plage = .Range("A2:A197")
Set plage1 = .Range("C2:C197")
For Each cel In plage
If cel.Offset(0,6).value < 500 Then
if cel.Offset(0,7).Value=1 and cel.Offset(0,8).Value=1
then cel.Offset(0,9).Value=1.68
End If
if cel.Offset(0,7).Value=1 and cel.Offset(0,8).Value=0
then cel.Offset(0,9).Value=1.68
End If
if cel.Offset(0,7).Value=2 and cel.Offset(0,8).Value=0
then cel.Offset(0,9).Value=1.67
End If
if cel.Offset(0,7).Value=2 and cel.Offset(0,8).Value=1
then cel.Offset(0,9).Value=2
End If
End If
If cel.Offset(0,6).value < 1000 and cel.Offset(0,6).value > 500
if cel.Offset(0,7).Value=1 and cel.Offset(0,8).Value=1
then cel.Offset(0,9).Value=1.5
End If
if cel.Offset(0,7).Value=1 and cel.Offset(0,8).Value=0
then cel.Offset(0,9).Value=1.6
End If
if cel.Offset(0,7).Value=2 and cel.Offset(0,8).Value=0
then cel.Offset(0,9).Value=1.67
End If
if cel.Offset(0,7).Value=2 and cel.Offset(0,8).Value=1
then cel.Offset(0,9).Value=2.2
End If
End If
Application.Goto Reference:="Macro1"
End SubEnfait ce que je veux faire c'est de tester si la longueur est < 500 alors :
Si terminals = 1 et seals= 1 alors time=1,68
Si terminals= 1 et seals = 0 alors time=..
si terminals = 2 et seals = 1 alors ..
si terminals = 2 et seals = 0 alors..
Si longueur > 500 et longueur < 1000 alors
// meme traitement
f
Bonjour,
Essaie comme cela
Sub Test()
Dim DerLig As Long
Dim Cel As Range, Plage As Range
Application.ScreenUpdating = False
With Sheets("Sheet1")
DerLig = .Range("A" & Rows.Count).End(xlUp).Row
Set Plage = .Range("A2:A" & DerLig)
For Each Cel In Plage
If Cel.Offset(0, 6).Value < 500 Then
'Si terminals = 1 et seals= 1 alors time=1,68
If Cel.Offset(0, 7).Value = 1 And Cel.Offset(0, 8).Value = 1 Then
Cel.Offset(0, 9).Value = 1.68
End If
'Si terminals = 1 et seals= 0 alors time=1,68
If Cel.Offset(0, 7).Value = 1 And Cel.Offset(0, 8).Value = 0 Then
Cel.Offset(0, 9).Value = 1.68
End If
'Si terminals = 2 et seals= 0 alors time=1,67
If Cel.Offset(0, 7).Value = 2 And Cel.Offset(0, 8).Value = 0 Then
Cel.Offset(0, 9).Value = 1.67
End If
'Si terminals = 2 et seals= 1 alors time=2
If Cel.Offset(0, 7).Value = 2 And Cel.Offset(0, 8).Value = 1 Then
Cel.Offset(0, 9).Value = 2
End If
ElseIf Cel.Offset(0, 6).Value < 1000 Then
If Cel.Offset(0, 7).Value = 1 And Cel.Offset(0, 8).Value = 1 Then
Cel.Offset(0, 9).Value = 1.5
End If
If Cel.Offset(0, 7).Value = 1 And Cel.Offset(0, 8).Value = 0 Then
Cel.Offset(0, 9).Value = 1.6
End If
If Cel.Offset(0, 7).Value = 2 And Cel.Offset(0, 8).Value = 0 Then
Cel.Offset(0, 9).Value = 1.67
End If
If Cel.Offset(0, 7).Value = 2 And Cel.Offset(0, 8).Value = 1 Then
Cel.Offset(0, 9).Value = 2.2
End If
End If
Next Cel
End With
End SubA+
n
Ah mais oui ça marche !!!!!
merci infiniment frangy.