Align two different sets of shapes in a cell range with command button

nosman

New Member
Joined
May 6, 2016
Messages
8
I am trying to align shapes to a specific range such as range(B2:Z2), currently the shapes align to where ever the command button is placed. I don't want the command button to be treated as a shape. In addition I want to have a set of rectangle shapes and a rounded rectangle shapes. I need the rectangles to align in range(B2:Z2) and the rounded rectangle to align in range(B6:Z6) with one or two command buttons. I have the code below for aligning shapes horizontally, but it works on all shapes rather than specific shapes.


Code:
Private Sub CommandButton21_Click()Dim Shp(1 To 100) As Shape
Dim x As Integer, y As Integer
Dim totWidth As Double




' counts number of shapes on page


x = ActiveSheet.Shapes.Count
For y = 1 To x
    If Shp(1) Is Nothing Then
        Set Shp(1) = ActiveSheet.Shapes(y)
        totWidth = Shp(y).Width
    Else
        Set Shp(y) = ActiveSheet.Shapes(y)
        Shp(y).Left = Shp(1).Left + totWidth
        Shp(y).Top = Shp(1).Top
        totWidth = totWidth + Shp(y).Width
    End If
Next y
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top