CurrentRegion - Doesn't work when function referenced in worksheet cell

BlaineG

New Member
Joined
Mar 27, 2013
Messages
4
CurrentRegion is most handy in many cases, however I have (sadly) just discovered, it apparently has limitations.
I have boiled this down to its simplest form for posting purposes. This is not my real code, but it demonstrates the challenge.

If the function (below) is called from another function or subroutine, or, if it is simply run "stand alone" it does what I expect, it targets cell C3, expands the range, and the resultant address is displayed as B3:D6 (no problem).

However, if the function is used by inserting the formula "=MyFun()" into a cell in the spreadsheet, the CurrentRegion seems to be completely ignored and the function displays, and returns, simply "C3" (ignoring the ".CurrentRegion" portion of the s1 assignment).

Can someone share why this happens? What am I missing?
Thank you!!


Function MyFun() As String
Dim s1 As String
s1 = Worksheets("SHEET1").Range("C3").CurrentRegion.Address
MsgBox s1
MyFun = s1
End Function



-- removed inline image ---



 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top