Excel get range for named dynamic range (OFFSET)

本小妞迷上赌 提交于 2019-12-12 01:22:06

问题


hi I have a data Validation for a dropdown cell on Sheet1, the List is a named dynamic range whose equation is: =OFFSET(Sheet2!$J$3,0,0,COUNTA(Sheet2!$J:$J)-2,1)

Works fine.

But now I want to get the Excel cell reference for this; in my example the range is sheet2!$j$3:$j$30. I need that string to put into a Range reference

I've done this by parsing but slows down my spreadsheet


回答1:


A VBA solution to the question you asked might be:

Dim x as String
With Worksheets("Sheet2")
    x = "'" & .Name & "'!" & .Range("J3", .Range("J3").Offset(Application.WorksheetFunction.CountA(.Columns("J")) - 2, 0)).Address
End With
'The value of variable x is now the address you asked for

but maybe what you are really trying to do is:

Dim rng As Range
With Worksheets("Sheet2")
    Set rng = .Range("J3:J" & .Range("J" & .Rows.Count).End(xlUp).Row)
End With
'rng will now be a Range object referring to everything in
' column J, starting at row 3 and ending at the last
' non-blank cell in column J



回答2:


You don't have to do anything special. The formula will return a valid range.



来源:https://stackoverflow.com/questions/39360167/excel-get-range-for-named-dynamic-range-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!