title: Excel file to count total rows in VBA
body: <p>I am writing a VBA macro to count the number of rows in <code>sheet2</code> of Excel file</p>
  
  <pre><code>Dim cnt As Integer 
  Dim i As Integer
  
  cnt = Range("Sheet2").Rows.Count ' giving error at this row
  For i = 2 To cnt
      t1 = "A" + CStr(i)
      t2 = "B" + CStr(i)
  Next i
  </code></pre>
  
  <p>But it giving error:</p>
  
  <blockquote>
    <p>Method 'Range' of object '_global' failed </p>
  </blockquote>