+ Reply to Thread
Results 1 to 10 of 10

Centering Image in Merged Range

  1. #1
    Registered User
    Join Date
    04-03-2015
    Location
    NY NY
    MS-Off Ver
    Office 365
    Posts
    38

    Centering Image in Merged Range

    My end goal is to center an image in a merged range. I found code that will allow me to center an image in a cell but I cant seem to figure out how to (or even if its possible to) modify it to work on a merged range instead of a single cell.

    If anyone has any idea about how to modify this code, or a different way all together to go about this any help would be much appreciated!

    In the attached file ctrl+w will center an object in the selected cell provided that the top right corner of the object is located in that cell.
    Attached Files Attached Files

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

    Re: Centering Image in Merged Range

    Hi there,

    Take a look at the attached version of your workbook and see if it does what you need. It uses the following code:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Centering Image in Merged Range

    I have replaced ActiveCell with a object variable use to keep the code short. And it now uses the merge area of the activecell


    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    04-03-2015
    Location
    NY NY
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Centering Image in Merged Range

    Thanks Greg, this is exactly what I was trying to accomplish, I just didn't have enough VBA experience to code it! But looking at your code, it makes total sense.

  5. #5
    Registered User
    Join Date
    04-03-2015
    Location
    NY NY
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Centering Image in Merged Range

    Spoke a bit too soon - if I want to assign this to a hotkey instead of a button, how would I go about doing that?

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

    Re: Centering Image in Merged Range

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    You're welcome - glad I was able to help.


    To assign a hotkey:

    go into the VBA CodeModule and delete or comment-out the "Option Private Module" statement;

    go back into Excel and use Alt+F8 to display the Macro menu;

    select the "CheckShapeAndRange" macro and then click on the "Options . . ." button;

    on the "Macro Options" menu, enter whichever key you wish to use, and then click on "OK".


    Hope this helps.


    Best regards,

    Greg M



    P.S.


    But looking at your code, it makes total sense

    Thank you - that's a very nice compliment to receive.
    Last edited by Greg M; 10-15-2019 at 02:41 PM. Reason: P.S. added

  7. #7
    Registered User
    Join Date
    04-03-2015
    Location
    NY NY
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Centering Image in Merged Range

    AHHHH - I was wondering why it wasn't showing up in the macro menu. Removed that and it popped right up. I did a quick Google search and understand the basic use of that command but im curious why you included it in the first place?

    Also, it only seems to be working on the first range I use it on. I get an error saying there is no shape in the range if I try to execute it on a second range. In the attached it works as expected in range 1, but in 2 and 3 it insists there isn't a shape there. Any thoughts?

    Thanks,
    Simon
    Attached Files Attached Files

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

    Re: Centering Image in Merged Range

    Hi again Simon,

    Dang it all! That's what happens when you test your code on a "nice little workbook" instead of on a "real" one!

    The attached workbook contains a new version of the "CheckShapeAndRange" routine (shown below), and appears to do what you need.

    Please Login or Register  to view this content.

    Regarding:


    but I'm curious why you included it in the first place?

    I normally include the "Option Private Module" statement to prevent macros being made available to "curious Users" via the Macro menu - I prefer to make macros available via CommandButtons on a worksheet or icons on the Ribbon.


    Hope the above helps - as always, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-03-2015
    Location
    NY NY
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Centering Image in Merged Range

    That did it! Thanks again for all your help. And for the explanation - makes sense in terms of keeping prying hands off your code!

    Best,
    Simon

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

    Re: Centering Image in Merged Range

    You're welcome - glad to have helped out.

    Feel free to shout if there's anything else you need.

    Regards,

    Greg M

+ 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. [SOLVED] Clear merged and non-merged cells in named range.
    By IMM Tech in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2018, 12:37 PM
  2. Centre image (horizontally) across merged range
    By Fialko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2017, 02:22 AM
  3. Replies: 1
    Last Post: 10-22-2016, 04:27 AM
  4. [SOLVED] Pasting an image into selected merged cells. VBA to size automatically to selected range
    By DCC_PD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2015, 09:57 AM
  5. automatically fit an image into merged cells for full width of merged cells
    By Marcin4111 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-18-2014, 03:12 PM
  6. automatically fit an image into merged cells
    By dave in forum Excel General
    Replies: 3
    Last Post: 11-18-2014, 06:26 AM
  7. Centering image (horizontally) in Range
    By speedone in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-04-2011, 10:51 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