Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active September 19, 2020 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/aad3c0bb33f8a61a0ccc4687f8809833 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/aad3c0bb33f8a61a0ccc4687f8809833 to your computer and use it in GitHub Desktop.
Function get_center_cell_of_shape(s As Shape) As Range
Dim center_x As Double: center_x = s.Left + s.Width / 2
Dim center_y As Double: center_y = s.Top + s.Height / 2
Dim r As Range: Set r = s.TopLeftCell
Do Until r.Left <= center_x And center_x <= r.Left + r.Width
Set r = r.Offset(columnoffset:=1)
Loop
Do Until r.Top <= center_y And center_y <= r.Top + r.Height
Set r = r.Offset(rowoffset:=1)
Loop
Set get_center_cell_of_shape = r
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment