1

I'm working on a sheet where I create checkboxes.

I use the following code to create the checkbox:

Sub AddCheckbox()

Dim vert As Integer
Dim MyTop  As Integer
vert = Sheets("Overview").Range("P2").Value

Sheets("Database").Activate
MyTop = 15 * (vert - 1)
    ActiveSheet.CheckBoxes.Add(770, MyTop, 1, 1).Select
        With Selection
            .Caption = ""
            .Value = xlOff
            .LinkedCell = "K" & vert
            .Display3DShading = False
        End With

End Sub

This piece works perfectly until I call it from some other part of the script. At this point I'm getting the message "name is not defined" (roughly translated). Why?

When the script directly starts, a checkbox is created and the linked cell works fine. When the script is called, a checkbox is created with a caption and without link to the cell.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Stefan
  • 11
  • 3
  • make sure both sheets *`Overview`* and *`Database`* exist. check that there always is a **valid** value in `Overview` sheet `Range("P2")`. Make sure variable `MyTop` exist. `.LinkedCell` may need to be qualified (sheet name before K). Can't think of anything else –  Dec 16 '13 at 10:17
  • Alright, checked all your suggestions, except for one i'm not 100% sure. "Make sure MyTop exist" with following code should be sufficient, right? `Dim MyTop As Integer` combined with `MyTop = 15 * (vert -1)` Sorry for the poor formatting – Stefan Dec 16 '13 at 10:24
  • yes you have the `MyTop` sorry Ive missed that. I can't reproduce the error so I can't work out in what circumstances you're getting the error :/ can you explain when the error happens? –  Dec 16 '13 at 10:34
  • apparently I figured it out. Since I Activate the `Database` sheet, I had to Activate the `Overview` sheet again in the other script. It´s a bit of magic to me though :) Thanks for the suggestions anyway! – Stefan Dec 16 '13 at 10:43
  • [INTERESTING READ](http://stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select) – Siddharth Rout Dec 16 '13 at 14:33
  • Thanks, interesting read indeed! – Stefan Dec 16 '13 at 22:10

0 Answers0