title: In Excel VBA, what are the differences between "IsNull()" and "var = Null"?
body: <p>Consider the following VBA function:</p>
  
  <pre><code>Function getFirstColumn(Optional sheetName As String) As Long
      'In particular the IF statement below.
      If sheetName = "" Or sheetName = Null Then sheetName = ActiveWorkbook.ActiveSheet.Name
      With ActiveWorkbook.Worksheets(sheetName)
          getFirstColumn = .Cells.Find("*", .Cells(1), xlFormulas, xlWhole, xlByColumns, xlNext).Column
          If Err &lt;&gt; 0 Then getFirstColumn = 0
      End With
  End Function
  </code></pre>
  
  <p>When using this function, I don't have problems when using it from a second opened sheet.</p>
  
  <p>But when the code is changed to it's function-based equivalent, <code>'If IsEmpty(sheetName) Or IsNull(sheetName) Then sheetName = ActiveWorkbook.ActiveSheet.Name</code>, I get problems if I try to use the function from a sheet that doesn't own it:</p>
  
  <blockquote>
    <p>Erro em tempo de execução '9':<br>
    Subscrito fora do intervalo.</p>
  </blockquote>
  
  <p>What are the differences between them? And why is such error triggered exactly?</p>