+ Reply to Thread
Results 1 to 10 of 10

How to fit rectangle with big size in a middle of a range

  1. #1
    Registered User
    Join Date
    12-06-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    21

    How to fit rectangle with big size in a middle of a range

    Hi everyone,

    After searching I got my rectangle placed center of Range("A1:J18"). But if I change size of width and height to lagre numbers, my rectangle goes outside the box (Range("A1:J18")).
    Is there anyway to keep my rectangle fit inside the range but still scale regard to size of width and height? Below is the code center rectangle in a range. I also attached file that I am doing. Hope you guys can help me. It is much appreciated. Nice day all

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by gaului; 09-04-2017 at 08:42 AM.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: How to fit rectangle with big size in a middle of a range

    Untested, but perhaps something like...

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-06-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to fit rectangle with big size in a middle of a range

    Thanks quekbc, I tested and it doesn't work

  4. #4
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: How to fit rectangle with big size in a middle of a range

    Can you give more info than that? What about it that doesn't work?

  5. #5
    Registered User
    Join Date
    12-06-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to fit rectangle with big size in a middle of a range

    I copy your red code to my file, then run it.
    I tested it with width = 600 , height = 500, and I also tested in small cases with width or height greater than maxwidth, maxheight. The rectangle still went outside the box.

  6. #6
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: How to fit rectangle with big size in a middle of a range

    Hmm... I can see the issue with width = 600 and height = 500 as my code will deal with one but ignore the other... so... try this.

    This should at most put the borders ON the box's line, but not outside.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-06-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to fit rectangle with big size in a middle of a range

    Thanks quekbc. It is working now . Can I ask you one more question? If the width or height with bigger size, it goes with exactly as same as maxwidth or maxheight, but the ruler then goes outside the box. Is there anyway to have padding or margin to have the rectangle and its height/width ruler inside the box?

  8. #8
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: How to fit rectangle with big size in a middle of a range

    You need to make sure your check the BeginY and EndY. If they are outside the box, move it inside. Something like...

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-06-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: How to fit rectangle with big size in a middle of a range

    Thanks quekbc. Actually, I understand your suggestion, but I don't know how to apply it into my code. Maybe I will work around with the first solution you gave.
    Anyway, your help is very appreciated. Thaks again and take care

  10. #10
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: How to fit rectangle with big size in a middle of a range

    hi gaului,

    I've added this line just before you create your horizontal line. I've also attached a sample file here.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Replies: 3
    Last Post: 02-17-2015, 05:16 PM
  2. [SOLVED] Passing a range to a sub from a shape (rectangle) on the worksheet
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-27-2013, 01:01 PM
  3. how to modify size of a drawn rectangle
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2010, 01:46 PM
  4. Generate Visio Doc- expand rectangle size
    By smiling_kk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2010, 02:29 AM
  5. Size of pasted range, size of clipboard ?
    By dpenny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2007, 12:57 PM
  6. [SOLVED] Code to get a Range RECTangle or PT
    By keepITcool in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-12-2005, 02:05 PM
  7. [SOLVED] Changeing cell size in the middle of a worksheet
    By JS in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-27-2005, 11:06 AM

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