+ Reply to Thread
Results 1 to 10 of 10

Resize picture to fit merged cell

  1. #1
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Resize picture to fit merged cell

    I have attempted to create a macro that resizes a picture based on the length and width of merged cells. I've ran into two problems: it only works on one picture per sheet (i.e., it will not let me run the same macro on a different picture but will instead resize the first picture again), and it does not fully fit the merged cells. I'm not sure about the first problem, but it seems it's not counting all the rows and columns when calculating the height and width. Any input would be great help!

    Sub Resize()
    Dim r As Range
    Set r = Application.InputBox("Click in the cell to hold the picture", Type:=8)
    On Error GoTo 0
    If r Is Nothing Then Exit Sub
    If r.Count > 1 Then Exit Sub
    ActiveSheet.Select
    With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
    .LockAspectRatio = True
    .Top = r.Top
    .Left = r.Left
    .Height = r.RowHeight * r.MergeArea.Rows.Count
    .Width = r.ColumnWidth * r.MergeArea.Columns.Count
    End With
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Resize picture to fit merged cell

    Hi,

    One way perhaps
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Resize picture to fit merged cell

    Richard,
    That's not doing anything for me at all. The picture stays in the same dimensions.

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    One way perhaps
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Resize picture to fit merged cell

    I have assumed that the top left pixel of your picture(s) is within the boundaries of the merged cells.

    It's difficult to advise further without seeing where your pictures are located in your workbook.

  5. #5
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Resize picture to fit merged cell

    I would prefer for the code to recognize pictures inserted anywhere on the worksheet. Also, it is now working to some extent once the picture is inside the boundaries of the cell. The new problem is that it resizes based on a single cell and not the range of merged cells. Appreciate your help again!

  6. #6
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Resize picture to fit merged cell

    Richard,
    I've attached a worksheet where the pictures would be located. As you can see the current code resizes it to fit only B46, but the worksheet I use would require merged columns at the least.
    Attached Files Attached Files

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Resize picture to fit merged cell

    Hi TitansGo,
    try to change this part of the Richard's code
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Resize picture to fit merged cell

    Nilem,
    Awesome. I made a few more changes below to the code and now it actually works with merged cells. The only other problem I have that needs to be resolved is that the code only works when part of the picture is in the top left cell in the merged cells. You have any ideas for being able to resize it from anywhere on the worksheet?

    Please Login or Register  to view this content.

  9. #9
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Resize picture to fit merged cell

    try this
    Please Login or Register  to view this content.
    edited
    oops, I did not read 'from anywhere on the worksheet'
    Last edited by nilem; 08-26-2016 at 11:57 AM.

  10. #10
    Registered User
    Join Date
    10-20-2015
    Location
    Alabama
    MS-Off Ver
    Excel 2013
    Posts
    29

    Re: Resize picture to fit merged cell

    Nilem,
    Oops indeed! It still requires the pictures to be within the boundaries of the merged cells. I'll play around with the code some more to see what I come with. Please feel free to do the same. I'm just working by trial and error at this point lol.

+ 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: 5
    Last Post: 03-29-2021, 03:01 AM
  2. Excel VBA to insert & resize picture based on cell url
    By shabeersa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2016, 03:54 AM
  3. Replies: 5
    Last Post: 09-11-2014, 02:30 PM
  4. Insert image and resize to fit merges selected cell (also merged cell)
    By acecarwash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2014, 09:55 AM
  5. [SOLVED] VBA help to move and resize a picture from one cell to another
    By markharris2004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2013, 07:04 AM
  6. Auto Resize Pasted Picture to merged cell
    By CyberPath in forum Excel General
    Replies: 2
    Last Post: 04-15-2012, 07:13 AM
  7. Paste picture in & have it resize to merged cells size
    By simonwilliams in forum Excel General
    Replies: 0
    Last Post: 10-02-2011, 03:12 PM

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