Locating command button

jonnynacker

New Member
Joined
Sep 11, 2014
Messages
46
Hey guys,
have a workbook which will continually hide and unhide command buttons so each time they must be located back to where they are needed. I am fine with locating them to a cell in the " top left corner" using this script for all the command buttons;

Code:
Sheet4.CommandButton98.Top = Sheet4.Range("D38").Top
Sheet4.CommandButton98.Left = Sheet4.Range("D38").Left

I want them to be located in the top right though, any suggestions?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,833
Office Version
  1. 2010
Platform
  1. Windows
Code:
    Dim r As Range

    With Sheet4
        Set r = .Range("D38")
        With .CommandButton98
            .Top = r.Top
            .Left = r.Left + r.Width - .Width
        End With
    End With
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,915
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You could use something like this after you determine the correct increment to use:

Sheet4.CommandButton98.IncrementLeft #

where # is the number of points of increment needed to move the button to the right side of the cell (yes, I know its IncrementLeft, but it will move right).

To calibrate you - column width is measured in characters. The default width is 8.43 which is 48 points.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,626
Messages
5,838,436
Members
430,547
Latest member
jopshio

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
Top