Hi - I thought I would quickly run through a dynamic named range.
Basically you are setting a name range that moves according to the data - this means that the Data you test needs to be assessed as either being Numeric or Text.
If it was numeric it would look to match a big number - it is unlikely to find this exceptionally large number and when it finishes trying it would have reached the bottom of the data set and we can use that to determin the last row. The same happens when we use text. If you were unsure which was bigger than you could have a simple IF statement picking which is bigger.
If the data was just in Column A and it was just numeric then it would be:
=Sheet1!$A$1:INDEX(Sheet1!$A:$A,MATCH(10^308,Sheet1!$A:$A,1),1)
Notice I go from A1 but this can be changed.
If the data was just in Column A and it was just text then it would be:
=Sheet1!$A$1:INDEX(Sheet1!$A:$A,MATCH(REPT("z",255),Sheet1!$A:$A,1),1)
If you wanted the range to extend to column AV but you were going to assess the data in column B to determin the range and the data in column B was numeric which I think your data is then it would be:
=Sheet1!$B$1:INDEX(Sheet1!$AV:$AV,MATCH(10^308,Sheet1!$B:$B,1),1)
I thought I would also mention if you don't know how many columns you have but it starts in column B and you have header text then you could have:
=Sheet1!$B$1:INDEX(Sheet1!$B:$XFD,MATCH(10^308,Sheet1!$B:$B,1),MATCH(REPT("z",255),Sheet1!$1:$1,1)-1)
Note - I had to -1 at the end as we started the range in Column B not column A so the column number is off by 1.
If you then wanted to use this range in VBA you need to DEFINE it, SET it then you can USE it. So your code would be something like:
Code:
Option Explicit
Public Sub CopyDynamicRange()
Dim drngNew As Excel.Range
Set drngNew = Sheet1.Range("drng_DynamicNamedRange")
Call drngNew.Copy(Destination:=Sheet2.Range("A1"))
Application.CutCopyMode = False
End Sub