title: Run-time error '1004': Method 'Range' of object '_worksheet' failed
body: <p>I am trying to write to a cell when a checkbox is marked using this sub</p>
  
  <pre><code>Sub CheckBox7_Click()
  If ws1.Shapes("Check Box 7").OLEFormat.Object.Value = 1 Then
  ws2.Range(comment).Offset(0, 2).Value = "1"
  Else
  ws2.Range(comment).Offset(0, 2).Value = "0"
  End If
  End Sub
  </code></pre>
  
  <p>But if I just open the sheet and click the checkbox I get the Run-time error '1004': Method 'Range' of object '_worksheet' failed error.</p>
  
  <p>I defined the variables at the top of the module:</p>
  
  <pre><code>Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Dim comment As String
  Dim rown As Integer
  </code></pre>
  
  <p>And I set the variables when the workbook opens:</p>
  
  <pre><code>Private Sub Workbook_Open()
  rown = 3
  comment = "F" &amp; rown
  Set ws1 = ThisWorkbook.Sheets("Rating test")
  Set ws2 = ThisWorkbook.Sheets("Comments test")
  End Sub
  </code></pre>
  
  <p>What is strange to me, if I first press a button with the following code in the module, I do not get the error anymore, even though it is the same code I put into the Workbook_open event:</p>
  
  <pre><code>Sub First_Comment()
  Set ws1 = ThisWorkbook.Sheets("Rating test")
  Set ws2 = ThisWorkbook.Sheets("Comments test")
  
      rown = 3
      comment = "F" &amp; rown
  
  End Sub
  </code></pre>
  
  <p>Thanks for the help, I am a VBA novice!</p>