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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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