peterghost
New Member
- Joined
- Oct 19, 2018
- Messages
- 3
Hi! I would like your help in a little problem that i have. I use this code to add checkboxes to a selected range of cells in excel and link them automatically with each cell (each checkbox is created in the center of its cell). However, if
the width or height of the cells is modified the checkboxes aren't autoadjusted to the new center of the cells. What do i need to add/change?
CODE:
Public Sub Add_ActiveX_Checkboxes()
Dim wks As Worksheet
Dim cell As Range, checkboxCells As Range
Dim objOLE As OLEObject
Set wks = ActiveSheet
Set checkboxCells = Application.Selection
Set checkboxCells = Application.InputBox("Range", "Analysistabs", checkboxCells.Address, Type:=8)
For Each cell In checkboxCells
Set objOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")
With objOLE
.Width = 12
.Height = 12
.Left = cell.Left + (cell.Width / 2) - (objOLE.Width / 2)
.Top = cell.Top + (cell.Height / 2) - (objOLE.Height / 2)
.Name = "Checkbox_" & cell.Address
.LinkedCell = cell.Worksheet.Name & "!" & cell.Address
'.Placement = xlMove
.Placement = xlMoveAndSize
.Object.Value = False
.Object.BackStyle = fmBackStyleTransparent
'.Object.BackStyle = fmBackStyleOpaque
.Object.TripleState = False 'True
.Object.Caption = ""
End With
Next
End Sub
the width or height of the cells is modified the checkboxes aren't autoadjusted to the new center of the cells. What do i need to add/change?
CODE:
Public Sub Add_ActiveX_Checkboxes()
Dim wks As Worksheet
Dim cell As Range, checkboxCells As Range
Dim objOLE As OLEObject
Set wks = ActiveSheet
Set checkboxCells = Application.Selection
Set checkboxCells = Application.InputBox("Range", "Analysistabs", checkboxCells.Address, Type:=8)
For Each cell In checkboxCells
Set objOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1")
With objOLE
.Width = 12
.Height = 12
.Left = cell.Left + (cell.Width / 2) - (objOLE.Width / 2)
.Top = cell.Top + (cell.Height / 2) - (objOLE.Height / 2)
.Name = "Checkbox_" & cell.Address
.LinkedCell = cell.Worksheet.Name & "!" & cell.Address
'.Placement = xlMove
.Placement = xlMoveAndSize
.Object.Value = False
.Object.BackStyle = fmBackStyleTransparent
'.Object.BackStyle = fmBackStyleOpaque
.Object.TripleState = False 'True
.Object.Caption = ""
End With
Next
End Sub