OVH Cloud OVH Cloud

Problème avec Range...

2 réponses
Avatar
Nosferalto
Bonjour !
Comme je viens de le preciser =E0 Pierre,
j'ai un souci sur le range.
j'ai une premiere boucle qui marche tres bien,
des qu'il attaque la 2eme
Je lui demande de selectionner une plage de cellule
qui commence par J1
Mais il reste "bloquer"sur I1...
y a t il un moyen de reinitialiser le range ou autre ?
Par avance merci pour votre aide.

' compte le nbr de cellule ds une colonne
Fin_Col =3D ""
Range("I1").Select
Fin_Col =3D Range("I1").SpecialCells
(xlCellTypeLastCell).Row
Fin_Col =3D Fin_Col + 1
MsgBox Fin_Col


Dim cellA As Range
Dim cellB
Dim Ad_cellA
Dim n
Dim cellBval
Dim cellAval
cellA =3D ""
cellB =3D ""
cellBval =3D ""
cellAval =3D ""
n =3D "0"


' --- Premiere boucle qui marche tr=E8s bien

cellB =3D Range("J1").Value
For Each cellA In Range(Range("I1"), Range("I65536").End
(xlDown))
MsgBox (cellA)
cellAval =3D cellA.Address

' For Each cellB In Range(Range("J1"), Range
("J65536").End(xlDown))
MsgBox "!!! ANCIEN !!! cellB : " & (cellB)
' cellB.Select
If n >=3D 1 Then
' cellB =3D ""
' cellBval =3D ""
cellB =3D Selection.Offset(rowOffset:=3D(n),=20
columnOffset:=3D1).Value
cellBval =3D Selection.Offset(rowOffset:=3D(n),=20
columnOffset:=3D1).Address

End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA =3D " & (cellA)
MsgBox "Valeur cellB =3D " & (cellB)
MsgBox "Ligne CellA num=E9ro =3D " &=20
(cellA.Row)
If cellA.Value =3D "Q" Then
If cellB =3D "7 : Won - In=20
force" Then
MsgBox "Valeur cellAval=20
=3D " & (cellAval)
Range(cellAval).Select
Selection.Interior.Color =3D=20
RGB(255, 0, 0) ' ---- 0.0.0 =3D noir
=20
MsgBox "Valeur cellbval=20
=3D " & (cellBval)
Range(cellBval).Select
Selection.Interior.Color =3D=20
RGB(255, 0, 0) ' ---- 0.0.0 =3D noir
=20
=20
Range("I1").Select
End If
Else
If cellA.Value =3D "S" Then
=20
' --- 1 - 10, 10B, 10C, 6A,=20
6B, 8A,8B, 8C, 10A, 10B, 10C, 10D
If cellB =3D "6 : Won - Not in=20
force" Or cellB =3D "6A : Won - Not confirmed" Or cellB=20
=3D "7 : Won - In force" Or cellB =3D "9 : Cancelled" Then
=20
MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color =3D=20
RGB(255, 0, 0)
=20
MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color =3D=20
RGB(255, 0, 0)
=20
Range("I1").Select
End If
End If
' Next Exit for
=20
=20
End If
' Exit For
Else
Exit For
End If
n =3D n + 1
Next
MsgBox "FIN The..."
Range("J1").Select


' --- 2 eme boucle ou se situe le probl=E8me :
cellA =3D ""
cellB =3D ""
cellAval =3D ""
cellBval =3D ""
n =3D "0"

cellB =3D Range("N1").Value
' --- !!! Dans la ligne ci-dessous je souhaiterais=20
selectionner la cellule "J1" _
Mais il me prend toujours la cellule cell - 1 cad "I1" _
la je ne vois vraiment pas... !!!
For Each cellA In Range(Range("J1"), Range("I65536").End
(xlDown))
If n >=3D 1 Then
cellB =3D Selection.Offset(rowOffset:=3D(n),=20
columnOffset:=3D3).Value
cellBval =3D Selection.Offset(rowOffset:=3D(n),=20
columnOffset:=3D3).Address
End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA =3D " & (cellA)
MsgBox "Valeur cellB =3D " & (cellB)
MsgBox "Ligne CellA num=E9ro =3D " &=20
(cellA.Row)
If cellA =3D "1 : New Project=20
Identified" Or cellA =3D "2 : Preliminary work/Pre-
qualification" Or cellA =3D "3 : Offer in preparation" Then
If IsEmpty(cellB) =3D False Then
MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color =3D=20
RGB(255, 204, 102)
=20
MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color =3D=20
RGB(255, 204, 102)
=20
=20
Range("J1").Select
End If
End If
' Exit For
Else
Exit For
End If
n =3D n + 1
Next

2 réponses

Avatar
John Fuss
Salut,

For Each cellB In Range(Range("J1"), Range
("J65536").End(xlDown))

faut que tu remplaces ton xlDown par un xlUp

quand on utilise Range("J65536").end(xlup).row

Voilà

John

"Nosferalto" a écrit dans le message de
news:1740201c38675$56b5da80$

Bonjour !
Comme je viens de le preciser à Pierre,
j'ai un souci sur le range.
j'ai une premiere boucle qui marche tres bien,
des qu'il attaque la 2eme
Je lui demande de selectionner une plage de cellule
qui commence par J1
Mais il reste "bloquer"sur I1...
y a t il un moyen de reinitialiser le range ou autre ?
Par avance merci pour votre aide.

' compte le nbr de cellule ds une colonne
Fin_Col = ""
Range("I1").Select
Fin_Col = Range("I1").SpecialCells
(xlCellTypeLastCell).Row
Fin_Col = Fin_Col + 1
MsgBox Fin_Col


Dim cellA As Range
Dim cellB
Dim Ad_cellA
Dim n
Dim cellBval
Dim cellAval
cellA = ""
cellB = ""
cellBval = ""
cellAval = ""
n = "0"


' --- Premiere boucle qui marche très bien

cellB = Range("J1").Value
For Each cellA In Range(Range("I1"), Range("I65536").End
(xlDown))
MsgBox (cellA)
cellAval = cellA.Address

' For Each cellB In Range(Range("J1"), Range
("J65536").End(xlDown))
MsgBox "!!! ANCIEN !!! cellB : " & (cellB)
' cellB.Select
If n >= 1 Then
' cellB = ""
' cellBval = ""
cellB = Selection.Offset(rowOffset:=(n),
columnOffset:=1).Value
cellBval = Selection.Offset(rowOffset:=(n),
columnOffset:=1).Address

End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA = " & (cellA)
MsgBox "Valeur cellB = " & (cellB)
MsgBox "Ligne CellA numéro = " &
(cellA.Row)
If cellA.Value = "Q" Then
If cellB = "7 : Won - In
force" Then
MsgBox "Valeur cellAval
= " & (cellAval)
Range(cellAval).Select
Selection.Interior.Color RGB(255, 0, 0) ' ---- 0.0.0 = noir

MsgBox "Valeur cellbval
= " & (cellBval)
Range(cellBval).Select
Selection.Interior.Color RGB(255, 0, 0) ' ---- 0.0.0 = noir


Range("I1").Select
End If
Else
If cellA.Value = "S" Then

' --- 1 - 10, 10B, 10C, 6A,
6B, 8A,8B, 8C, 10A, 10B, 10C, 10D
If cellB = "6 : Won - Not in
force" Or cellB = "6A : Won - Not confirmed" Or cellB
= "7 : Won - In force" Or cellB = "9 : Cancelled" Then

MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color RGB(255, 0, 0)

MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color RGB(255, 0, 0)

Range("I1").Select
End If
End If
' Next Exit for


End If
' Exit For
Else
Exit For
End If
n = n + 1
Next
MsgBox "FIN The..."
Range("J1").Select


' --- 2 eme boucle ou se situe le problème :
cellA = ""
cellB = ""
cellAval = ""
cellBval = ""
n = "0"

cellB = Range("N1").Value
' --- !!! Dans la ligne ci-dessous je souhaiterais
selectionner la cellule "J1" _
Mais il me prend toujours la cellule cell - 1 cad "I1" _
la je ne vois vraiment pas... !!!
For Each cellA In Range(Range("J1"), Range("I65536").End
(xlDown))
If n >= 1 Then
cellB = Selection.Offset(rowOffset:=(n),
columnOffset:=3).Value
cellBval = Selection.Offset(rowOffset:=(n),
columnOffset:=3).Address
End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA = " & (cellA)
MsgBox "Valeur cellB = " & (cellB)
MsgBox "Ligne CellA numéro = " &
(cellA.Row)
If cellA = "1 : New Project
Identified" Or cellA = "2 : Preliminary work/Pre-
qualification" Or cellA = "3 : Offer in preparation" Then
If IsEmpty(cellB) = False Then
MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color RGB(255, 204, 102)

MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color RGB(255, 204, 102)


Range("J1").Select
End If
End If
' Exit For
Else
Exit For
End If
n = n + 1
Next
Avatar
nosferlato
Re-moi !

Je viens de trouver !
alors là j'ai honte !
j'ai oublier de changer un i en j...
M'enfin !
Nosferalto



-----Message d'origine-----

Bonjour !
Comme je viens de le preciser à Pierre,
j'ai un souci sur le range.
j'ai une premiere boucle qui marche tres bien,
des qu'il attaque la 2eme
Je lui demande de selectionner une plage de cellule
qui commence par J1
Mais il reste "bloquer"sur I1...
y a t il un moyen de reinitialiser le range ou autre ?
Par avance merci pour votre aide.

' compte le nbr de cellule ds une colonne
Fin_Col = ""
Range("I1").Select
Fin_Col = Range("I1").SpecialCells
(xlCellTypeLastCell).Row
Fin_Col = Fin_Col + 1
MsgBox Fin_Col


Dim cellA As Range
Dim cellB
Dim Ad_cellA
Dim n
Dim cellBval
Dim cellAval
cellA = ""
cellB = ""
cellBval = ""
cellAval = ""
n = "0"


' --- Premiere boucle qui marche très bien

cellB = Range("J1").Value
For Each cellA In Range(Range("I1"), Range("I65536").End
(xlDown))
MsgBox (cellA)
cellAval = cellA.Address

' For Each cellB In Range(Range("J1"), Range
("J65536").End(xlDown))
MsgBox "!!! ANCIEN !!! cellB : " & (cellB)
' cellB.Select
If n >= 1 Then
' cellB = ""
' cellBval = ""
cellB = Selection.Offset(rowOffset:=(n),
columnOffset:=1).Value
cellBval = Selection.Offset(rowOffset:=(n),
columnOffset:=1).Address

End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA = " & (cellA)
MsgBox "Valeur cellB = " & (cellB)
MsgBox "Ligne CellA numéro = " &
(cellA.Row)
If cellA.Value = "Q" Then
If cellB = "7 : Won - In
force" Then
MsgBox "Valeur cellAval
= " & (cellAval)
Range(cellAval).Select
Selection.Interior.Color
=

RGB(255, 0, 0) ' ---- 0.0.0 = noir

MsgBox "Valeur cellbval
= " & (cellBval)
Range(cellBval).Select
Selection.Interior.Color
=

RGB(255, 0, 0) ' ---- 0.0.0 = noir


Range("I1").Select
End If
Else
If cellA.Value = "S" Then

' --- 1 - 10, 10B, 10C, 6A,
6B, 8A,8B, 8C, 10A, 10B, 10C, 10D
If cellB = "6 : Won - Not in
force" Or cellB = "6A : Won - Not confirmed" Or cellB
= "7 : Won - In force" Or cellB = "9 : Cancelled" Then

MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color
=

RGB(255, 0, 0)

MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color
=

RGB(255, 0, 0)

Range("I1").Select
End If
End If
' Next Exit for


End If
' Exit For
Else
Exit For
End If
n = n + 1
Next
MsgBox "FIN The..."
Range("J1").Select


' --- 2 eme boucle ou se situe le problème :
cellA = ""
cellB = ""
cellAval = ""
cellBval = ""
n = "0"

cellB = Range("N1").Value
' --- !!! Dans la ligne ci-dessous je souhaiterais
selectionner la cellule "J1" _
Mais il me prend toujours la cellule cell - 1 cad "I1" _
la je ne vois vraiment pas... !!!
For Each cellA In Range(Range("J1"), Range("I65536").End
(xlDown))
If n >= 1 Then
cellB = Selection.Offset(rowOffset:=(n),
columnOffset:=3).Value
cellBval = Selection.Offset(rowOffset:=(n),
columnOffset:=3).Address
End If
MsgBox (cellA.Row)
If cellA.Row < Fin_Col Then
MsgBox "Valeur cellA = " & (cellA)
MsgBox "Valeur cellB = " & (cellB)
MsgBox "Ligne CellA numéro = " &
(cellA.Row)
If cellA = "1 : New Project
Identified" Or cellA = "2 : Preliminary work/Pre-
qualification" Or cellA = "3 : Offer in preparation" Then
If IsEmpty(cellB) = False Then
MsgBox (cellBval)
Range(cellBval).Select
Selection.Interior.Color
=

RGB(255, 204, 102)

MsgBox (cellAval)
Range(cellAval).Select
Selection.Interior.Color
=

RGB(255, 204, 102)


Range("J1").Select
End If
End If
' Exit For
Else
Exit For
End If
n = n + 1
Next
.