Range.Cells property syntax

前端 未结 1 384
时光说笑
时光说笑 2021-01-23 00:24

I\'m confused by the Range.Cells property. According to MSN documentation:

Range.Cells Property (Excel)

The syntax is supposed to be expression .Cells

1条回答
  •  一生所求
    2021-01-23 00:52

    When no dot . precedes a Cells or Range method, this is called an unqualified range reference; Excel's VBA wraps it automatically to the sheet that is currently active.

    Cells(1, 1) <==> Activesheet.Cells(1, 1)
    Range("A1") <==> Activesheet.Range("A1")
    

    However, this is considered bad practice and it should be avoided because it leads to random issues and bugs; the code's behavior depends on what sheet the user currently has on top in Excel's GUI. Experienced developers always avoid it as much as possible and use qualified ranges; ie

    Worksheets("someSheetName").Cells(1, 1).

    0 讨论(0)
提交回复
热议问题