Results 1 to 4 of 4

Fit picture to cell

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Crayford, kent
    MS-Off Ver
    Excel 2013
    Posts
    394

    Fit picture to cell

    Hi

    I am using a dynamic range to determine what picture to put into a cell, and have used a macro to try and fit the picture to the cell which is

    Public Sub FitPic()
     On Error GoTo NOT_SHAPE
     Dim PicWtoHRatio As Single
     Dim CellWtoHRatio As Single
     With Selection
     PicWtoHRatio = .Width / .Height
     End With
     With Selection.TopLeftCell
     CellWtoHRatio = .Width / .RowHeight
     End With
     Select Case PicWtoHRatio / CellWtoHRatio
     Case Is > 1
     With Selection
     .Width = .TopLeftCell.Width
     .Height = .Width / PicWtoHRatio
     End With
     Case Else
     With Selection
     .Height = .TopLeftCell.RowHeight
     .Width = .Height * PicWtoHRatio
     End With
     End Select
     With Selection
     .Top = .TopLeftCell.Top
     .Left = .TopLeftCell.Left
     End With
     Exit Sub
     NOT_SHAPE:
     MsgBox "Select a picture before running this macro."
     End Sub
    BEFORE I GET A WARNING, THE POST WONT LET ME PUT CODE TAGS OR FORMULA TAGS AROUND THE TEXT???????

    but this doesnt work? my cell has =ShowMyPic in it

    Which is picking up the linked cell from a combo box

    Is there a way i can get the picture to autofit the cell?
    Last edited by alansidman; 10-04-2013 at 05:25 AM. Reason: added code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] sizing picture same picture in multiple sheets macro clean up
    By martinez77 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2013, 10:14 PM
  2. VBA for Picture insert at particular worksheet range. Picture name derived from cell.
    By Douglas2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2013, 01:16 AM
  3. Creating macro to insert a picture by including specific picture name & path
    By NissaFrenchRamsteyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-09-2012, 05:40 AM
  4. [SOLVED] macro: insert picture based on workbook location, not picture root path.
    By NicksDad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2012, 07:47 AM
  5. Insertion of picture by xls formula/ naming the picture with multiple selection crite
    By luckiest man in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2011, 12:11 AM

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