centering checkboxes vertical in cell

R

ranswert

I used this code to center a checkbox vertically in a cell and I got a "run
time error object required message". This is the code I entered:

Sub cbox()
Dim cell As Range
Dim chk As Excel.CheckBox
Set cell = ActiveCell
Set chk = wsh.CheckBoxes.Add(cell.Left + 0.3 * cell.Width, cell.Top,
cell.Width, cell.Height)
chk.Height = cell.Height - 1.5

End Sub
 
M

merjet

I suspect 'wsh' is not set. For example, insert:
Set wsh = ActiveSheet

Hth,
Merjet
 
D

Dave Peterson

You didn't declare wsh or tell excel what wsh was.

But since you know the cell that the checkbox goes in, then you can use:

Set chk = cell.parent.CheckBoxes.Add(cell.left + 0.3, ....

The parent of the cell is the worksheet that it's located on.
 

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

Similar Threads

checkbox 2
checkbox 5
check boxes 7
checkbox centered in cell 4
check box Error 2
Inserting Image based on cell value - Help 0
I need help again 4
Excel 2007 VBA shape fill colour problem 0

Top