Results 1 to 10 of 10

Centering Image in Merged Range

Threaded View

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

    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.

    
    
    Sub CheckShapeAndRange()
    
        Dim rTargetRange    As Range
        Dim bShapeFound     As Boolean
        Dim rCell           As Range
        Dim shp             As Shape
    
        If TypeName(Selection) = "Range" Then
    
              Set rTargetRange = Selection
    
              For Each shp In ActiveSheet.Shapes
    
                  bShapeFound = False
    
                  For Each rCell In rTargetRange.Cells
    
                      If rCell.Address = shp.TopLeftCell.Address Then
                          bShapeFound = True
                          Exit For
                      End If
    
                  Next rCell
    
                  If bShapeFound = True Then
    
                        Call CentreShape(rTargetRange:=rTargetRange, shp:=shp)
                        Exit For
    
                  End If
    
              Next shp
    
              If bShapeFound = False Then
                  MsgBox "The selected cells do not contain a Shape", vbExclamation
              End If
    
        Else: MsgBox "Select a range before using this feature", vbExclamation
    
        End If
    
    End Sub

    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

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. [SOLVED] 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