View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default CheckBoxes and the Split function

Hi Howard,

Am Sat, 20 Jun 2015 00:47:11 -0700 (PDT) schrieb L. Howard:

So the inputbox window would look like: 5,H,4,MyCkBox

Want 5 checkboxes
In column H
Starting at row 4
Named "MyCkBox" (no quotes, followed by a number)


modify the prompt for the inputbox.
Try:

Sub Add_Checkboxes()

Dim cBx As Long, aRow As Long
Dim CLeft As Double, CTop As Double, CHeight As Double, CWidth As Double
Dim MyBoxes As String
Dim varBoxes As Variant


MyBoxes = Application.InputBox(Prompt:="Enter the number of CheckBoxes," _
& " the column letter, the row number of the first row and the caption of" _
& " the CheckBoxes comma separated(Name of Check Box)", Title:="myValues", Type:=2)


Application.ScreenUpdating = False

varBoxes = Split(MyBoxes, ",")
aRow = CInt(varBoxes(2))

For cBx = 1 To CInt(varBoxes(0))
CLeft = Cells(aRow, varBoxes(1)).Left
CTop = Cells(aRow, varBoxes(1)).Top
CHeight = Cells(aRow, varBoxes(1)).Height
CWidth = Cells(aRow, varBoxes(1)).Width

ActiveSheet.CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select
With Selection
.Caption = varBoxes(3) & cBx
.Value = xlOff
.Display3DShading = False
End With

aRow = aRow + 2 ' for every other row else aRow + 1
Next cBx

Application.ScreenUpdating = True

End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional