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?
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,770
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,246
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,536
Messages
5,529,422
Members
409,875
Latest member
Khushal Bisht
Top