vendredi 21 octobre 2016

VBA checkboxes in the wrong place

Ive copied a VBA code from online to produce checkboxes within a range and link them to adjacent cells. The linked cells are in the correct place however the check boxes appear offset up and left by a few cells? I can't see anything in the code that might cause this? Im working on a mac.

Thanks for any help, Aaron

Option Explicit
Sub insertCheckboxes()

  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, _
          Width:=.Width, Left:=.Left, Height:=.Height)

        With myBox
          .LinkedCell = linkedColumn & myCell.Row
          .Caption = cboxLabel
          .Name = "checkbox_" & myCell.Address(0, 0)
        End With

        .NumberFormat = ";;;"
      End With

    Next myCell
  End With
End Sub




Aucun commentaire:

Enregistrer un commentaire