Insert a square in a cell with VBA

J

JayDe

Hi

I have a list in Excel 2007. I want to put a square to the right of some of
the list items. How can I do this with VBA.

The end user will see the list on a printout with square/checkbox in the
right column. The idea is that the end user should go thrue the list and
mark/check the items that he agrees on

Regards
JayDe
Norway
 
G

Gary''s Student

Just put a border around the cell:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/16/2010 by James Ravenswood
'

'
Range("E8").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End Sub
 
J

JayDe

Thank you for the answer.
But a border does not look at all like a checkbox, so I am not very happy
with that solution

JayDe
 
G

Gord Dibben

Expanding upon the macro that Dave Peterson wrote at the URL you were
pointed to................

Select the range of cells to the right of your list.

List of items in A1:A20

Select B1:B20 and run the macro.

Sub testme()
Dim mycell As Range
For Each mycell In Selection
On Error Resume Next
ActiveSheet.CheckBoxes("cb_" & mycell.Address(False, False)).Delete
On Error GoTo 0
With mycell
With ActiveSheet.CheckBoxes.Add(.Left, .Top, .Width, .Height)
.Name = "cb_" & mycell.Address(False, False)
.Caption = "Agree"
End With
End With
Next
End Sub


Gord Dibben MS Excel MVP
 
J

JayDe

Thank you guy's

This did the trick


JayDe



Gord Dibben said:
Expanding upon the macro that Dave Peterson wrote at the URL you were
pointed to................

Select the range of cells to the right of your list.

List of items in A1:A20

Select B1:B20 and run the macro.

Sub testme()
Dim mycell As Range
For Each mycell In Selection
On Error Resume Next
ActiveSheet.CheckBoxes("cb_" & mycell.Address(False, False)).Delete
On Error GoTo 0
With mycell
With ActiveSheet.CheckBoxes.Add(.Left, .Top, .Width, .Height)
.Name = "cb_" & mycell.Address(False, False)
.Caption = "Agree"
End With
End With
Next
End Sub


Gord Dibben MS Excel MVP



.
 

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