+ Reply to Thread
Results 1 to 4 of 4

automatically fit an image into merged cells

  1. #1
    dave
    Guest

    automatically fit an image into merged cells

    can anyone tell me how to insert an image into excel so it appears in the
    same place every time also so it resizes to the merged cells i have created

  2. #2
    JE McGimpsey
    Guest

    Re: automatically fit an image into merged cells

    one way:

    Insert the image then run this macro. Adjust the cell reference as
    desired:

    Public Sub PositionAndScalePic()
    Dim rArea As Range
    Dim dFactor As Double
    Set rArea = ActiveSheet.Range("J5").MergeArea
    With ActiveSheet.Pictures
    With .Item(.Count)
    .Top = rArea.Top
    .Left = rArea.Left
    dFactor = rArea.Width / .Width
    .Width = rArea.Width
    .Height = .Height * dFactor
    If .Height > rArea.Height Then
    dFactor = rArea.Height / .Height
    .Height = rArea.Height
    .Width = .Width * dFactor
    End If
    .Placement = xlMoveAndSize
    End With
    End With
    End Sub



    In article <[email protected]>,
    "dave" <[email protected]> wrote:

    > can anyone tell me how to insert an image into excel so it appears in the
    > same place every time also so it resizes to the merged cells i have created


  3. #3
    Registered User
    Join Date
    06-02-2014
    Posts
    88

    Re: automatically fit an image into merged cells

    Public Sub PositionAndScalePic()
    Dim rArea As Range
    Dim dFactor As Double
    Set rArea = ActiveSheet.Range("J5").MergeArea
    With ActiveSheet.Pictures
    With .Item(.Count)
    .Top = rArea.Top
    .Left = rArea.Left
    dFactor = rArea.Width / .Width
    .Width = rArea.Width
    .Height = .Height * dFactor
    If .Height > rArea.Height Then
    dFactor = rArea.Height / .Height
    .Height = rArea.Height
    .Width = .Width * dFactor
    End If
    .Placement = xlMoveAndSize
    End With
    End With
    End Sub
    Do you know how should I modify this code for uploaded picture to be scaled with locked aspect ratio for full width of merged cells?

    Regards,
    Marcin

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: automatically fit an image into merged cells

    Hi, Marcin4111,

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.


    And please use code-tags instead of quote-tags to display code.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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