Thread: Check boxes
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_2_] Dave Peterson[_2_] is offline
external usenet poster
 
Posts: 420
Default Check boxes

I like to shrink the column to the exact width of the checkbox -- and I make the
checkbox caption "", so that it's just a checkbox in the cell.

But you could fiddle around by offsetting the location of the checkbox with
something like:

Option Explicit
Sub InsertCheckBoxes()
'from Dave Peterson

Dim iCtr As Long

Const FirstRow As Long = 2
Const LastRow As Long = 18
Const CBXCol As Long = 3 'column C
Dim myOffset As Double

myOffset = 35


With ActiveSheet
.CheckBoxes.Delete 'nice for testing
For iCtr = FirstRow To LastRow
If .Cells(iCtr, 2).Value Like "*Pend*" Then
With .Cells(iCtr, CBXCol)
With .Parent.CheckBoxes.Add _
(Top:=.Top, _
Width:=.Width - myOffset, _
Left:=.Left + myOffset, _
Height:=.Height)
.Name = "cbx_" & Format(iCtr - 1, "000")
.Caption = ""
End With
End With
End If
Next iCtr
End With

End Sub

It worked ok with my test worksheet. But it'll depend on the width of column C.

For me, the checkbox had a white fill color, so I'm not sure what you mean.

But you may be able to determine your code by recording a macro when you change
the property that you want.

On 03/08/2011 21:23, Slim Slender wrote:
I'm using the following bit of code adapted from something I found
here to place some check boxes on a worksheet.

Sub InsertCheckBoxes()
'from Dave Peterson

Dim i As Long

Const firstrow As Long = 2
Const lastrow As Long = 18
Const cb_col As Long = 3 'column C

For i = firstrow To lastrow
With Cells(i, cb_col)
If Cells(i, 2).Value Like "*Pend*" Then
With
ActiveSheet.CheckBoxes.Add(.Left, .Top, .Width, .Height)
' .Name = "cb"& Format(i - 1, "000")
.Caption = ""
End With
End If
End With
Next i

End Sub

I've taken out a few bits I didn't need. What I find by right clicking
on a check box is that the "container" for the check box fills the
cell it is in and the check box is to the left. I was wondering if it
would be possible to programmatically reduce the size of the container
around the check box and make it flush right in the cell, oh, and one
other thing, can the container background be made white or opaque.


--
Dave Peterson