Getting a value from a named range in VBA

前端 未结 2 1576
情深已故
情深已故 2021-01-13 05:32

I want to retrieve a value from named range. Imagine a named range that has X columns and Y rows. I want to return a value, e.g., from column 2, row 3. The issue I experienc

相关标签:
2条回答
  • 2021-01-13 06:00

    Use this

    ThisWorkbook.Names("myNamedRange").RefersToRange(1,1)
    

    To get the value from the first cell in the named range "myNamedRange"

    With ThisWorkbook.Names you can access all named ranges of all the sheets within the current workbook. With RefersToRange you get a reference to the actual range.

    0 讨论(0)
  • 2021-01-13 06:14

    This looks like a good place to put a handy note (as it's a top search result):
    If you name a cell "TopLeft", then Sheets(1).Range("TopLeft").Value gets the contents, and Sheets(1).Range("TopLeft").Offset(2,3).Value gets the value from 2 down, 3 across from there.

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