Last active
September 19, 2020 23:17
-
-
Save zakuroishikuro/aad3c0bb33f8a61a0ccc4687f8809833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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