Forum Discussion
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?
Muchas gracias.
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
5 Replies
- Juliano-PetrukioBronze Contributor
There is no such feature.;
The closest you can get to it is selecting "Snap to grid" option when clicking over the image:
Image Format > Arrange > Aling >Snap to grid
You can also align using the image as references and try the different options (Left,Right, center, etc.)
- Marchal1979Copper ContributorMuchas gracias Juliano-Petrukio por tu tiempo y respuesta. Eso ya lo he probado y no me convence demasiado. He mirado por la web y se puede hacer a través de Macros en la VBA.
He probado algunos pero o dan error o no lo realizan correctamente en toda la tabla. Tienes conocimiento de algún macro que solvente esto?- Juliano-PetrukioBronze 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