+ Reply to Thread
Results 1 to 8 of 8

Parent Of A Range Object

  1. #1
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Parent Of A Range Object

    Hi all, and a very happy new year to everyone!

    The Parent property of a Range object should always return a Worksheet object, right?

    Well that's what I always thought until I received a "Type Mismatch" error when running the following code:

    Please Login or Register  to view this content.

    It appears that the Parent object of a Range object returned as the TopLeftCell property of a Shape object, is not the Worksheet object, but the SHAPE object. This can be seen from the following code:

    Please Login or Register  to view this content.

    I suppose that the above is not really illogical, but it probably is unexpected.

    Hope this might help someone from the head-banging I endured while trying to sort out the above. (Oh yes, it's very simple when it's all sorted out, but not so simple beforehand! )

    Regards,

    Greg M

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Parent Of A Range Object

    always return a Worksheet object, right
    Not necessarily...All depends on the Parent-Child correlation...Controls live inside other controls...
    As I understand...Parent will reference the control preceding as you have alluded to above...
    Not all controls have children though...
    Then again...I might be wrong...Perhaps they aren't married and choose not to have kids lol...
    Last edited by Sintek; 01-01-2025 at 09:16 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Valued Forum Contributor
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (24 H2) 64 Bit
    Posts
    1,187

    Re: Parent Of A Range Object

    Isn't it just;

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Parent Of A Range Object

    Simply...
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Parent Of A Range Object

    Hi Sintek & Haluk,

    Many thanks for your responses, but errrmmm . . . didn't I already say:

    Please Login or Register  to view this content.

    Meanwhile, the plot thickens!

    The attached workbook contains the following code:

    Please Login or Register  to view this content.
    The worksheet contains a Rounded Rectangle and an MSForms CommandButton, to each of which is assigned the macro "ShowParentName". Each of these is recognised as a Shape object.

    Clicking on the Rounded Rectangle displays the name of the Rounded Rectangle, and then displays the name of the Worksheet.

    Clicking on the MSForms CommandButton displays the name of the Worksheet, and then displays the name of the Workbook.


    So, apparently the Parent property of a Range object returned by the TopLeftCell property of a Shape object:

    is a Shape object when that Shape object is a Rounded Rectangle, and

    is a Range object when that Shape object is an MSForms CommandButton.

    Curiouser and curiouser

    Regards,

    Greg M
    Attached Files Attached Files

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Parent Of A Range Object

    If you specifically want the worksheet, use the Range's .Worksheet property.

    Also, that is not an MSForms.CommandButton. It's a native Excel Form button.
    Last edited by romperstomper; 01-06-2025 at 10:57 AM.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Parent Of A Range Object

    Hi romperstomper,

    Many thanks for your reply.

    Ok on using the Worksheet property, but the post was more about pointing out the differences associated with the type of Shape object involved, rather than finding something which would return the correct object.




    Also, that is not an MSForms.CommandButton. It's a native Excel Form button

    That indeed is a distinction of which I was unaware until now - chaque jour on apprend quelque chose!


    Thanks again,

    Greg M
    Last edited by Greg M; 01-06-2025 at 05:03 PM. Reason: Typo corrected

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Parent Of A Range Object

    Just once again...One of Excel's "Ghost in the Machine Issues"
    I personally always assumed it was the preceding link for all objects...
    But like I said...
    Perhaps they aren't married and choose not to have kids lol...
    Suggestion...Work around the issue...Like you have done...
    One day...one problem at a time...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. workbook object vs range object in accessing named variables
    By whburling in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-05-2022, 08:56 PM
  2. How can I determine the index of a Point object within it's parent array?
    By XmisterIS in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-28-2020, 09:18 AM
  3. Parent child - object doesn't support this property or method
    By Rajkumarin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2016, 05:48 PM
  4. Using the Parent property of the Borders Object
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2013, 09:53 PM
  5. What Worksheet (Parent) was my Range selected from?
    By ShawnW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2013, 04:46 PM
  6. [SOLVED] Parent child relationships(working out parent item) for each item
    By grphillips in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-21-2013, 05:58 AM
  7. In Procedure: When use Actual Range Object vs Create Local Object Using Set
    By Filibuster in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-20-2012, 02:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1