Need to know how to size an ActiveX button to be the same size as the cell underneath it

Foo_Man_Chu

Board Regular
Joined
Jul 22, 2010
Messages
79
Hi all,
It's been a long time since I've been in here, I'm hoping everyone will be patient with me. I'm using Excel 2013. I have an ActiveX Button control in my spreadsheet. For the life of me I can't figure out how to make the button the same size as the cell it is on top of, meaning the cell the button is in front of (if the button sized correctly you wouldn't be able to see the cell because it would be completely blocked out by the button). Any help that can be given would be very much appreciated.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try:-
Code:
Private Sub CommandButton1_Click()
With CommandButton1
    .Top = .TopLeftCell.Top
    .Left = .TopLeftCell.Left
    .Width = .TopLeftCell.Width
    .Height = .TopLeftCell.Height
End With
End Sub
 
Upvote 0
Thanks for the quick reply MickG. Unfortunately that's not exactly what I want. I need to create the button on the spreadsheet and have the button cover the cell exactly before the spreadsheet even runs, not have it resized based off of a button click event. Anyone else? Thanks
 
Upvote 0
Try this:-
NB:- Change range "R" to suit.
Code:
[COLOR="Navy"]Sub[/COLOR] MG03Oct31
[COLOR="Navy"]Dim[/COLOR] nBut [COLOR="Navy"]As[/COLOR] Object
[COLOR="Navy"]Dim[/COLOR] R [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] R = Range("B2")
[COLOR="Navy"]Set[/COLOR] nBut = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
        , DisplayAsIcon:=False, Left:=103.8, Top:=51, Width:=72, Height:=24)
        nBut.Top = R.Top
        nBut.Left = R.Left
        nBut.Width = R.Width
        nBut.Height = R.Height
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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