Forum Discussion
Marchal1979
Nov 25, 2021Copper Contributor
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...
- Nov 25, 2021
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
Juliano-Petrukio
Nov 25, 2021Bronze Contributor
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
Marchal1979
Nov 25, 2021Copper Contributor
PERFECTO!!! Muchísimas gracias!!!
- Juliano-PetrukioNov 25, 2021Bronze ContributorAny time my friend.
Once it solves your problem, dont forget to flag it as solved and hit the like button.