I am trying to get a range corresponding to the region returned by CTRL-A
when on cell B3
, which is B3:J9
for the setup below :
I have the following code to do so, which uses CurrentRegion in a function :
Option Explicit
Function TestY(msg As Range) As Range
Dim rg As Range, tl As Range
Set tl = msg.Cells(1)
Debug.Print tl.Row, tl.Column
Set rg = tl.CurrentRegion
Debug.Print rg.Count, rg.Cells(rg.Count).Row, rg.Cells(rg.Count).Column
End Function
However the debug log below shows that this does not work, tl.CurrentRegion
is just the same as msg.Cells(1)
:
3 2
1 3 2
Why is CurrentRegion
not working here and how can I fix it to return the same as CTRL-A
when on B3
?