title: Excel VBA Get Count of Non-Empty Rows in Range
body: <p>I know this has been asked at least a dozen times, but of all those questions the solutions seemed to be tailored or simply created an error in my code. For some reason I get an error when I try and reference a range from a different worksheet. Below is my code. I have two worksheets (tabs). One has a button to launch my code <code>MENU</code>, the other is the data I am trying to read and write to <code>RAW</code>. All I am trying to do is find out how many rows of data the sheet has so I can loop through the rows and make changes. For some reason I can't wrap my head around it or something.</p>
  
  <pre><code>Private Sub CommandButton21_Click()
    Dim wbCurrent As Workbook
    Dim wsCurrent As Worksheet
  
    Set wbCurrent = ThisWorkbook
    Set wsCurrent = wbCurrent.Worksheets("RAW")
  
    Dim i As Long
    Dim siteCol As Long
  
    siteCol = Range("I" &amp; Rows.Count).End(xlUp).Row
    For i = 1 To siteCol
      wsCurrent.Range("I" &amp; i) = "MARKED"
    Next i
    Range("I1") = siteCol
  End Sub
  </code></pre>