Forum Discussion

Marchal1979's avatar
Marchal1979
Copper Contributor
Nov 25, 2021
Solved

Centrar imagen en celda EXCEL

Buenos días a mailto:tod@s, Necesito que unas imágenes que he colocado en una tabla EXCEL se centren con su celda correspondiente tanto en horizontal como verticalmente. ¿Puede alguien ayudarme? M...
  • Juliano-Petrukio's avatar
    Juliano-Petrukio
    Nov 25, 2021

    Marchal1979 

    Sure it is possible using vba. But what is important to know is that the size of the picture or the size of the cell matters.

     

    You can try the following code considering the range A1:A100

     

    Sub ArrangeImages()
        Dim shp As Shape, rng As Range, shpRow As Long
        
        Set rng = Range("A1:A100")
        For Each shp In ActiveSheet.Shapes
            If Not Intersect(Range(shp.TopLeftCell.Address), rng) Is Nothing Then
                shpRow = shp.TopLeftCell.Row
            
                With shp
                    .Top = Range("A" & shpRow).Top + (Range("A" & shpRow).Height - .Height) / 2
                    .Left = Range("A" & shpRow).Left + (Range("A" & shpRow).Width - .Width) / 2
                End With
            
            End If
        Next
    End Sub

     

     

Resources