title: Excel VBA User-Defined Function: Get Cell in Sheet Function was Called In
body: <p>I have a user-defined function in Excel that I run in multiple sheets.  I am trying to use <code>Cells(i, j)</code> to pull the value of cells by their row and column <strong>in the sheet in which my function is called</strong>.  Instead, <code>Cells(i, j)</code> pulls the value of cell [i,j] in the <strong>active sheet</strong> when I hit the 'Calculate Now' button, and auto-calculation does not work.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>The full function is below, not sure if it's needed to answer my question.</p>
  
  <pre><code>Option Explicit
  Option Base 1
  Option Compare Text
  
  Function recordString(ByVal width As Integer, ByVal height As Integer, ByVal firstCell As Range) As String
      Application.Volatile
  
      Dim tempString As String
      tempString = ""
      Dim i As Integer
      Dim j As Integer
      For i = firstCell.Row To firstCell.Row + height - 1
          For j = firstCell.Column To firstCell.Column + width - 1
              If IsEmpty(Cells(i, j)) Then
                  tempString = tempString &amp; "0"
              Else
                  tempString = tempString &amp; "1"
              End If
          Next j
      Next i
      recordString = tempString
  End Function
  </code></pre>