In VBA the Rows property has a weird behavior

前端 未结 3 1206
南旧
南旧 2021-01-22 04:04

I am trying to figure out how to work on a specific row among a big range. However it appears that a range created with the rows property does not behave the same as a simple ra

3条回答
  •  无人及你
    2021-01-22 04:32

    This is how I would work with rows and specific cells within those rows. The only real difference is the use of .Cells():

    Sub WorkingWithRows()
        Dim rng As Range, rngRow As Range
        Set rng = Sheet1.Range("A1:C3")
    
        For Each rngRow In rng.Rows
            Debug.Print rngRow.Cells(1, 1).Address
            Debug.Print rngRow.Cells(1, 2).Address
            Debug.Print rngRow.Cells(1, 3).Address
        Next rngRow
    End Sub
    

    which returns:

    $A$1
    $B$1
    $C$1
    $A$2
    $B$2
    $C$2
    $A$3
    $B$3
    $C$3
    

    As you would expect

提交回复
热议问题