Place commandbuttons in a specific cell

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
Say row 1 height is 60 and button height is 30

CommandButton 1 in cell BP1 at the top (BP is column 68)
CommandButton 2 in cell BP1 below Button 1

.OLEObjects("Commandbutton1").Top = .Cells(1, 68).Top ' place in top of cell
.OLEObjects("Commandbutton1").Left = .Cells(1, 68).Top


.OLEObjects("Commandbutton2").Top = .Cells(1, 68).??? ' ?? Halfway down ??
.OLEObjects("Commandbutton2").Left = .Cells(1, 68).Top

An additional nice feature would be to actually "fit" the button to whatever the width of the column is
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Assuming you have two active-x command buttons named CommandButton1 and CommandButton2 (change names to suit) on the active sheet, this will position them one above the other and size then to fill the specified cell.
Code:
Sub Position2ButtonsIn1Cell()
Const WhatCell As String = "BP1"   'change cell to suit
Dim Btn1 As OLEObject, Btn2 As OLEObject
Set Btn1 = ActiveSheet.OLEObjects("Commandbutton1")
Set Btn2 = ActiveSheet.OLEObjects("Commandbutton2")
With Btn1
    .Top = Range(WhatCell).Top
    .Left = Range(WhatCell).Left
    .Width = Range(WhatCell).EntireColumn.Width
    .Height = Rows(Range(WhatCell).Row).Height / 2
End With
With Btn2
    .Top = Btn1.Top + Rows(Range(WhatCell).Row).Height / 2
    .Left = Range(WhatCell).Left
    .Width = Range(WhatCell).EntireColumn.Width
    .Height = Rows(Range(WhatCell).Row).Height / 2
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
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