我怎样才能移动一个形状,使其中心排列在excel VBA单元格左边缘

我有一组形状,我现在可以将其移动到参考单元格的左上angular,但是我需要将形状的中间与此左边缘alignment。 只有“顶”和“左”参数,没有“中”有没有这样做?

我可以移动到左边,然后根据列宽增加x的量,但是这看起来好像很长时间了?

Sub Macro4() Dim x Set x = Range("A2") Sheet1.Shapes("Group 9").Left = Sheet1.Cells(13, x).Left Sheet1.Shapes("Group 9").Top = Sheet1.Cells(13, x).Top End Sub 

更新:

我的代码现在如下所示:

用Sheet1

  .Shapes("Group 9").Top = rng.Top .Shapes("Group 9").Left = rng.Left - (.Shapes("Group 9").Width / 2) + (rng.Width / 2) End With 

其中达到以下

在这里输入图像说明

不过我需要做到这一点:

在这里输入图像说明

因此input的date为红色意味着形状中心与第11行的单元格的右边缘alignment,与此时的date相匹配R11

这将使您的形状在所定义的范围上居中,并根据需要进行修改。

 Dim rng As Range Set rng = Range("D15") With Sheet1 .Shapes("Group 9").Left = rng.Left - (.Shapes("Group 9").Width / 2) + (rng.Width / 2) .Shapes("Group 9").Top = rng.Top - (.Shapes("Group 9").Height / 2) + (rng.Height / 2) End With