.CurrentRegion does not return current region when used with one celled range object but does if ActivecCell is the same cell

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
855
Office Version
  1. 365
Platform
  1. Windows
I am trying to use .CurrentRegion with a range object with one cell, in this case cell D2. I confirm that the range object -- rAnchorCellChartData -- is set with Debug.Print as shown below. When trying to get the current region with that range object (rAnchorCellChartData.CurrentRegion) the result is the range with one cell. If I activate the same cell then .CurrentRegion returns the correct range when used with ActiveCell (ActiveCell.CurrentRegion).

I must be missing something basic?

VBA Code:
Debug.Print "rAnchorCellChartData = " & rAnchorCellChartData.Address
Debug.Print "rAnchorCellChartData.CurrentRegion = " & rAnchorCellChartData.CurrentRegion.Address
Debug.Print "ActiveCell = " & ActiveCell.Address
Debug.Print "ActiveCell.CurrentRegion = " & ActiveCell.CurrentRegion.Address

Result
rAnchorCellChartData = $D$2
rAnchorCellChartData.CurrentRegion = $D$2
ActiveCell = $D$2
ActiveCell.CurrentRegion = $C$1:$I$3
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Unfortunately, I can't reproduce the error...
VBA Code:
Sub O_Jim()

    Dim rAnchorCellChartData As Range
    Set rAnchorCellChartData = Sheet1.Range("$D$2")
    
    Debug.Print "rAnchorCellChartData = " & rAnchorCellChartData.Address
    Debug.Print "rAnchorCellChartData.CurrentRegion = " & rAnchorCellChartData.CurrentRegion.Address

End Sub

Leads to this in the immediate window:
VBA Code:
rAnchorCellChartData = $D$2
rAnchorCellChartData.CurrentRegion = $C$1:$I$3
 
Upvote 0
I'd have to suspect the two cells are on different sheets. What does this output?

VBA Code:
Debug.Print "rAnchorCellChartData = " & rAnchorCellChartData.Address
Debug.Print "rAnchorCellChartData.CurrentRegion = " & rAnchorCellChartData.CurrentRegion.Address(external:=true)
Debug.Print "ActiveCell = " & ActiveCell.Address(external:=true)
Debug.Print "ActiveCell.CurrentRegion = " & ActiveCell.CurrentRegion.Address
 
Upvote 0
Solution
RoryA. Indeed there were two different sheets involved. I feel pretty lame. I was creating a chart based on data in one sheet then I changed the sheet where the chart and data are to be located. So I was trying to get .CurrentRegion for a cell with nothing around it in the previous sheet which is now empty. Thank you for responding to my post! Sometimes a second opinion works wonders, even for very simple stuff.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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