Results 1 to 6 of 6

Centering image (horizontally) in Range

Threaded View

  1. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Centering image (horizontally) in Range

    Try this:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim i As Long
    
        If Target.Cells.Count > 1 Then Exit Sub
    
        If Not Intersect(Target, Me.Range("B3:B5")) Is Nothing Then
            Me.Range(Target, "B6").ClearContents
        End If
    
        For i = 1 To 3
            If Not Intersect(Target, Range("rngDisplayName" & i)) Is Nothing Then
                InsertPicFromFile1 _
                        sFile:=Range("rngFileLocation" & i).Value, _
                        r:=Range("rngPicDisplayCells" & i), _
                        bFitH:=True, _
                        sPic:="MyDVPic" & i
            End If
        Next i
    End Sub
    
    Sub InsertPicFromFile(sFile As String, _
                          r As Range, _
                          bFitH As Boolean, _
                          sPic As String)
        With r.Worksheet
            On Error Resume Next
            .Shapes(sPic).Delete
            On Error GoTo 0
    
            With .Pictures.Insert(Filename:=sFile)
                If bFitH Then .Height = r.Height
                .Left = r.Left + r.Width / 2 - .Width / 2
                .Top = r.Top
                .Name = sPic
            End With
        End With
    End Sub
    Last edited by shg; 02-04-2011 at 10:51 AM.

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