N° de ligne dans boucle for each cell in rng

Bonjour,

je suis en train d'écrire une petite macro.

Ma macro me pose un souci. Je cherche à obtenir et à stocker dans la ligne correspondante à cell.

et je ne vois pas pourquoi, mais j'e n'y arrive pas. La macro bloque sur For each cell in rng.... et parfois quand cela passe cette ligne, impossible d'obtenir le numéro de la ligne .

Sub import()

Dim myrow As Long

Dim rng, cell As Range

myrow = Cells(3, 1).End(xlUp).Row

rng = Range(Cells(3, 1), Cells(myrow, 1))

For Each cell In rng

i = cell.Row

Next

end sub

Bonsoir racouet56, le forum,

A tester à tout hasard.....

  myrow = Cells(Rows.Count, 1).End(xlUp).Row
Set rng = Range(Cells(3, 1), Cells(myrow, 1))

Cordialement,

Bonjour,

Un exemple à adapter :

Public Sub import()
Dim lastRow As Long, lRow As Long
Dim rng As Range, Cell As Range
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        Set rng = .Cells(3, 1).Resize(lastRow - 2)
    End With
    For Each Cell In rng
        lRow = Cell.Row
        '...
    Next
End Sub

Merci à tous les deux. J'ai testé et approuvé.

Super boulot.

Rechercher des sujets similaires à "ligne boucle each rng"