title: VBA calling same function gives 2 different answers
body: <p>I have a function that gives me the last open row, that I call form 2 worksheets. When I call the function I get a different answers from each sheet. The one gives me the correct value, and the other worksheet gives me a value that is one less. I have tried breaking the function down, but in the end the difference comes in at the second half of the main row (the long row), where I use <code>Abs</code>. </p>
  
  <p>I probably did not explain it very well, but the code runs with a button from two different sheets, and looks at the same data on one of the two sheets. Meaning, the code runs on the <strong>exact same data</strong> with different results, depending on the button I press. (Both buttons call the exact same macro to run the code)</p>
  
  <p>I got the code from a website that showed all the ways that a person can get the last open row from a worksheet. </p>
  
  <p>My code:</p>
  
  <pre><code>Public Function lastOpenRow(sheetName) As Long
      lastOpenRow = 1
      With sheetName
          For a = 1 To 50
              Count = Worksheets(sheetName).Cells(Rows.Count, a).End(xlUp).Offset(Abs(Cells(Rows.Count, 1).End(xlUp).value &lt;&gt; ""), 0).Row
              If lastOpenRow &lt; Count Then
                  lastOpenRow = Count
              End If
          Next a
          MsgBox "The lastOpenRow and Count = " &amp; lastOpenRow &amp; " " &amp; Count
  
      End With
  End Function
  </code></pre>
  
  <p>Any idea why I get two different answers?</p>