Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is why. When you say this:</p> <pre><code>Dim startCell, iCell As Range </code></pre> <p>you <em>think</em> you've done this:</p> <pre><code>Dim startCell As Range, iCell As Range </code></pre> <p>but what you've <em>really</em> done is this:</p> <pre><code>Dim startCell 'As Variant, by default Dim iCell As Range </code></pre> <p>This is a classic VBA mistake. Most VBA programmers have made it, and that's why most VBA programmers fall back on declaring only one variable per <code>Dim</code> statement (i.e. one per line). Otherwise it's way too easy to make that mistake, and difficult to spot it afterwards. </p> <p>So with <code>Dim startCell</code> you've implicitly declared your variable as Variant type (equivalent to <code>Dim startCell As Variant</code>). </p> <p>When you then say this:</p> <pre><code>Set startCell = Cells(iCell.Row + 1, iCell.Column) </code></pre> <p>the Variant acquires the type of the thing on the right hand side of the reference assignment (Range). However, when you say this:</p> <pre><code>startCell = Cells(iCell.Row + 1, iCell.Column) </code></pre> <p>without the <code>Set</code> keyword, you're not assigning a reference, but a value to the variable <code>startCell</code>, which now acquires the type of the value on the right hand side. What is that type? Well, the default property of a Range object is <code>Value</code>, so you're going to get the type of <code>Cells(iCell.Row + 1, iCell.Column).Value</code>. If that cell contains a string, then you'll get a string. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload