ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   centering checkboxes vertical in cell (https://www.excelbanter.com/excel-programming/403538-centering-checkboxes-vertical-cell.html)

ranswert

centering checkboxes vertical in cell
 
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



Vergel Adriano

centering checkboxes vertical in cell
 
wsh is not defined. Try replacing wsh with ActiveSheet.

--
Hope that helps.

Vergel Adriano


"ranswert" wrote:

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



merjet

centering checkboxes vertical in cell
 
I suspect 'wsh' is not set. For example, insert:
Set wsh = ActiveSheet

Hth,
Merjet



Dave Peterson

centering checkboxes vertical in cell
 
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.


ranswert wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 05:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com