title: sub declaration visual Basic
body: <p>I am really new with <a href="/questions/tagged/vba" class="post-tag" title="show questions tagged 'vba'" rel="tag">vba</a>, so please forgive my slaughtering of the code. I'm trying to write a macro for excel (my first one), and I get "statement invalid outside of type block" (pointing at the first line). Here is my code:</p>
  
  <pre><code>Sub MakeHTMLTable()    
     Worksheets("Sheet1").Activate
     endRow As Integer
  
  For Count = 1 To 200
      For CountY = 1 To 200
        If (!ActiveSheet.Cells(Count, CountY).Value.IsEmpty) Then
         ActiveSheet.Cells(Count, CountY).Value = "&lt;td&gt;" + ActiveSheet.Cells(Count, CountY).Value + "&lt;/td&gt;"
        End If
      Exit For
  Exit For
  
  For i = 1 To 200
      If (!ActiveSheet.Cells(i, 1).Value.IsEmpty()) Then
          ActiveSheet.Cells(i, 1).Value = "&lt;tr&gt;" + ActiveSheet.Cells(i, 1)
      End If
  Exit For
  
  For x = 1 To 200
      If (!ActiveSheet.Cells(x, 1).Value.IsEmpty()) Then
          endRow = x
      End If
  Exit For
  
  For countAgain = 1 To 200
      If (!ActiveSheet.Cells(x, countAgain).Value.IsEmpty()) Then
          ActiveSheet.Cells(x, countAgain).Value = ActiveSheet.Cells(x, countAgain).Value + "&lt;/tr&gt;"
      End If
  Exit For
  End Sub
  </code></pre>
  
  <p>I really don't understand, as the debugger fails on the line of computer generated code without even making it to mine. Have I missed ending an <code>If</code>" or <code>For</code> block?</p>
  
  <p>I also realize that I'm probably reinventing the wheel. Any help on more appropriate built in functions would be appreciated.</p>