title: Generic function procedure working with different workbooks
body: <p>I am trying to get better coding practice and using generic function.<br>
  I am working with several workbooks from a master file. 
  For example if I want to get the last row I am using the following line of code.  </p>
  
  <pre><code>LastRow=Range("A" &amp; Rows.Count).End(xlUp).Row 
  </code></pre>
  
  <p>To retrieve the value with a function I build the function:  </p>
  
  <p>-Function 1</p>
  
  <pre><code>Function GetLastRow() As Integer
  GetLastRow = Range("A" &amp; Rows.Count).End(xlUp).Row
  End Function 
  </code></pre>
  
  <p>Now from my <code>Sub Main()</code> I want to use <code>GetLastRow()</code> for different workbooks or worksheets. I think it is not a good thing to <code>Activate</code> the workbook before calling my function.  </p>
  
  <p>Then should I transmit each time the workbook name and worksheet number to my function and change my function to:  </p>
  
  <p>-Function 2</p>
  
  <pre><code>Function GetLastRowIn(sWb As String, iWs As Integer) As Integer
  GetLastRowIn = Workbooks(sWb).Worksheets(iWs).Range("A" &amp; Rows.Count).End(xlUp).Row
  End Function
  </code></pre>
  
  <p>Or is there a better/simpler way to transmit the workbook and worksheet in which I want to apply the function while keeping it with no argument as in Function 1?</p>
  
  <p>Thanks for your answers!  </p>