JacksonTriggs
New Member
- Joined
- Nov 4, 2021
- Messages
- 20
- Office Version
- 365
- Platform
- MacOS
Hi,
Despite a previous similar post on this subject, it was recommended I post a newer thread question because the original is quite old. I have very limited knowledge about VBA/macros.
I have an Excel spreadsheet with about 20 rows and 2 columns. The first column has an image in each row, however, they're not centered in their respective cells. I would like to fix this. I tried one of the VBA codes from that post (quoted below) but it only does a single, active cell instead of all images in the entire column. Also, when I try to repeat that Macro on a separate cell/image, it forces an error (sorry, I lost track of that code).
Screenshot of my spreadsheet:
Hoping someone might be able to help please. Thank in advance!
Despite a previous similar post on this subject, it was recommended I post a newer thread question because the original is quite old. I have very limited knowledge about VBA/macros.
I have an Excel spreadsheet with about 20 rows and 2 columns. The first column has an image in each row, however, they're not centered in their respective cells. I would like to fix this. I tried one of the VBA codes from that post (quoted below) but it only does a single, active cell instead of all images in the entire column. Also, when I try to repeat that Macro on a separate cell/image, it forces an error (sorry, I lost track of that code).
Screenshot of my spreadsheet:
Hoping someone might be able to help please. Thank in advance!
Code:
Code:Const inDebug As Boolean = False Sub CenterPictureIfInActiveCell() 'If the Top-Left corner of any Picture is located within the Active Cell 'Then center the picture within the Active Cell Dim Pic As Picture For Each Pic In ActiveSheet.Pictures If inDebug Then MsgBox Pic.Name If isInBetween(ActiveCell.Left - 1, ActiveCell.Left + ActiveCell.Width, Pic.Left) And _ isInBetween(ActiveCell.Top - 1, ActiveCell.Top + ActiveCell.Height, Pic.Top) _ Then Pic.Left = ActiveCell.Left + ((ActiveCell.Width - Pic.Width) / 2) Pic.Top = ActiveCell.Top + ((ActiveCell.Height - Pic.Height) / 2) End If Next Pic End Sub Function isInBetween(lowVal As Long, hiVal As Long, targetVal As Long, Optional Inclusive As Boolean = True) As Boolean 'Return TRUE if the targetVal is between the lowVal and hiVal (Inclusive optional) isInBetween = False