+ Reply to Thread
Results 1 to 9 of 9

Auto Fit Rows that are Merged.

  1. #1
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Question Auto Fit Rows that are Merged.

    Hi all,

    I'm trying to auto fit rows that are merged. I have tried this code:
    Please Login or Register  to view this content.
    But end up with a "Run-time 91" error. "Object variable or With Block variable not set." The debug then highlights "If Target.MergeCells Then".

    I'm new to VBA and am unsure how to personalise this VBA (it was written for someone else).
    Thank you in advance

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Fit Rows that are Merged.

    Autofit doesn't work on merged cells for some reason... I don't know if there is a solution out there...
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Re: Auto Fit Rows that are Merged.

    Hi AndyLitch,
    Thanks for the feedback - was thinking no one would answer me!!

    There appears to be a number of macros out there for it, but I just don't know how to personalise it for my sheet. I'm just too new to VBA to read the macro. I've tried the one in the original post and also this:

    Please Login or Register  to view this content.
    Thanks again for the feedback.

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Fit Rows that are Merged.

    I've tested it on my system... If you enter data into a merged cell and there is overspill it automatically sets the height.

    The only change I've made is the event subroutine

    Please Login or Register  to view this content.
    It seems to be working ok

  5. #5
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Re: Auto Fit Rows that are Merged.

    Hi AndyLitch,
    Thank you again for posting. I've been absolutely stumped on this one. I ran the macro again, as you had amended it and it first comes up with an error that the 'argument is not optional'. i added Optional to the first line and now it comes up with the same error as before. This time the debugger pointing to 'If .MergeCells And .WrapText Then'.

    Any ideas anyone? Thank you once again AndyLitch. Nic

  6. #6
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Re: Auto Fit Rows that are Merged.

    bump no response

  7. #7
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Fit Rows that are Merged.

    Like I say it works fine on my version of Excel so I'm a bit stumped...

    You can try substituting

    Please Login or Register  to view this content.
    to try and help identify which is causing the problem

  8. #8
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Re: Auto Fit Rows that are Merged.

    Hi AndyLitch,

    Thank you so much for your reply. I have finally got the macro working on a tester sheet, but it resizes the each row within the merged cell to the size of the content. Therefore, the cell it resizes to is too big and has a heap of extra space in it..

    I'll keep playing. I appreciate your time and assistance.

    Regards, Nic

  9. #9
    Registered User
    Join Date
    04-05-2013
    Location
    Perth, Australia
    MS-Off Ver
    2013
    Posts
    30

    Re: Auto Fit Rows that are Merged.

    Hi all,

    I have found a code that works on one of my sheets, but not the other. I'll past the code below for those interested.

    Please Login or Register  to view this content.
    Thanks very much!
    Last edited by scrawl.to.me; 04-15-2013 at 01:32 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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