Placing button at cell's location

G

Greg Lovern

I'm creating buttons in VBA, trying to place them at a given cell's
location, using the Top and Left properties of the cell. It works well
enough near the top of a worksheet, but as I go further and further
down the rows, the button is getting placed further and further below
the top of the cell.

For example, at row 121, the cell's Top property was about 1530, but
if I place a button at the top of row 121, that button has a Top
property of about 1500, which is between the tops of rows 123 and 124.

I've been doing this with the old Forms buttons to enable creating
them with parameters, so that all of the buttons call into the same
function, but each with a different parameter (that part is working
fine). But I tried it with ActiveX buttons too and got the same
problem with the button's Top property not being the same as the row
or cell's Top property.

What do I need to do to place these buttons at the top of a given row?


FWIW, I haven't tested whether the same problem exists with the Left
property. These buttons are all going into column B, so this isn't
really an issue with the horizontal placement.


Thanks,

Greg
 
G

Greg Lovern

What do I need to do to place these buttons at the top of a given row?

I've just discovered that I can get consistent placement by copying or
cutting the button, then selecting a cell at the desired row, and
pasting.

That seems to work well enough, but is there a more direct way to get
consistent placement?


Thanks,

Greg
 
G

Greg Lovern

For example, at row 121, the cell's Top property was about 1530, but
if I place a button at the top of row 121, that button has a Top
property of about 1500, which is between the tops of rows 123 and 124.

Sorry, I meant to say:

For example, at row 121, the cell's Top property was about 1530, but
if I place a button there, that button's top is between the tops of
rows 123 and 124. If I manually place a button at the top of row 121,
that button has a Top property of about 1500.

Greg
 
D

Dave Peterson

Is your zoom factor set to 100%?

If no, try changing to 100%, then add the buttons.
 
G

Greg Lovern

Is your zoom factor set to 100%?

If no, try changing to 100%, then add the buttons.


Thanks, that fixes it.

I had also just found that if I just move it right after creating it
(that is, move it to the very same location at which had I tried to
create it), like this:

MyButton.Top = MyRange.Top

That seems to work fine, without changing the zoom. Zoom was at 90%.


Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top