Convert sub Insert COLUMN of checkboxes to Insert ROW of checkboxes

AusSteelMan

Board Regular
Joined
Sep 4, 2009
Messages
208
Hi all,

I found the following code that inserts a single column, user entered range of checkboxes. (It works very well and saves much time for those interested)

Code:
Sub insertCheckboxes_OnCentre()
'Found via Chandoo.org at:
'http://www.terminally-incoherent.com/blog/2008/09/04/excel-adding-checkboxes-the-easy-way/
 
'modified to position the checkbox close to on centre horizontally of the cell
'with a width of 35 pixels and height of 17 pixels (standard height)
 
  Dim myBox As CheckBox
  Dim myCell As Range
  Dim cellRange As String
  Dim cboxLabel As String
  Dim linkedColumn As String
 
  cellRange = InputBox(Prompt:="Cell Range", _
    Title:="Cell Range")
 
  linkedColumn = InputBox(Prompt:="Linked Column", _
    Title:="Linked Column")
 
  cboxLabel = InputBox(Prompt:="Checkbox Label", _
    Title:="Checkbox Label")
 
  With ActiveSheet
    For Each myCell In .Range(cellRange).Cells
      With myCell
        Set myBox = .Parent.CheckBoxes.Add(Top:=.Top - (.Height / 6), _
            Width:=.Width, Left:=.Left + (.Width / 5.5), Height:=.Height / 4)
 
        With myBox
          [COLOR=red].LinkedCell = linkedColumn & myCell.Row[/COLOR]
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With
 
        .NumberFormat = ";;;"
      End With
 
    Next myCell
  End With
End Sub

As shown the LinkedCell is a concatenation of the user enter Column letter and the current row number (myCell.Row)

What I would like to do is insert a ROW of checkboxes. So I modified the code to this:

Code:
Sub insertCheckboxes_OnCentre_InRows_FixedColAndRow()
'Found via Chandoo.org at:
'http://www.terminally-incoherent.com/blog/2008/09/04/excel-adding-checkboxes-the-easy-way/
 
'modified to position the checkbox close to on centre horizontally of the cell
'with a width of 35 pixels and height of 17 pixels (standard height)
 
'modified (trying too!!) to produce checkboxes in rows instead of columns
 
  Dim myBox As CheckBox
  Dim myCell As Range
  Dim cellRange As String
  Dim cboxLabel As String
  Dim linkedRow As Integer  [COLOR=red]'have also tried this as String, but did no work either[/COLOR]
 
  cellRange = InputBox(Prompt:="Cell Range", _
    Title:="Cell Range")
 
  linkedRow = InputBox(Prompt:="Linked Row", _
    Title:="Linked Row")
 
  cboxLabel = InputBox(Prompt:="Checkbox Label", _
    Title:="Checkbox Label")
 
  With ActiveSheet
    For Each myCell In .Range(cellRange).Cells
      With myCell
        Set myBox = .Parent.CheckBoxes.Add(Top:=.Top - (.Height / 6), _
            Width:=.Width, Left:=.Left + (.Width / 5.5), Height:=.Height / 4)
 
        With myBox
          [COLOR=red].LinkedCell = Cells(linkedRow, myCell.Column)[/COLOR]
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With
 
        '.NumberFormat = ";;;"
      End With
 
    Next myCell
  End With
End Sub

Prodincing the actual checkboxes in rows is working ok.

The problem is in generating the linked cell address. I obliviously cannot concatenate the row number and column number directly as it makes no sense. The
Code:
myCell.Column
gives the correct column number, but I need the letter so it work (or I need more knowledge on using the column number, either way)

So I tried using Cells(Row, Col) as shown above but still get LinkedCell="" (seen while stepping through code).

Now I don't think I know where to go. I appreciate any help anyone can provide to help me out.

Much thanks,
Darren
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I fixed it.

Code:
        With myBox
          .LinkedCell = Cells(linkedRow, myCell.Column)[COLOR=red].Address[/COLOR]
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With

Thanks to everyone who considered this problem anyway.

I'm still happy to take any improvement suggestions.

Regards,
Darren
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top