I need to simply count the number of areas on a sheet. The code I have is :
Sub areas()
Dim i As Long
i = Worksheets("Sheet2").Selection.Areas.Count
MsgBox i
End Sub
But for some reason I get the error message "Object doesn't support this property or method." I have no idea why. This code was basically just copied from the Microsoft website.
I can't even get the immediate window to print the Worksheets("Sheet2").Selection.Areas.Count
portion.
Any quick help? I am using Excel 2010.
Thanks.
Think of it like if anything after the dot is called on an object. It's like a chain.
An object is a class instance. A class instance supports some properties defined in that class type definition. It exposes whatever intelli-sense in VBE tells you (there are some hidden members but it's not related to this). So after each dot
.
you get intelli-sense (that white dropdown) trying to help you pick the correct action.(you can start either way - front to back or back to front, once you understand how this works you'll be able to identify where the problem occurs)
Type this much anywhere in your code area
you get help from VBE, it's a little dropdown called Intelli-sense
It lists all available actions that particular object exposes to any user. You can't see the
.Selection
member of theWorksheets()
class. That's what the error tells you exactly.If you look at the example on MSDN
It
activates
the sheet first then calls theSelection...
it's not connected together becauseSelection
is not a member ofWorksheets()
class. Simply, you can't prefix theSelection
What about
from HERE