title: Testing if a cell is empty in VBA
body: <p>I'm trying to write a module in VBA to take a worksheet containing the structure of a website and output into a worksheet two columns which have (column 1) the name of a page, and (column 2) the section of the site that page is in. (So I can make use of it in Visio)</p>
  
  <p>My existing worksheet contains a structure like this:</p>
  
  <pre><code>Root / Section / Sub-section / Page
  Root / Section / Page
  Root / Section / Sub-section / Sub-section / Page
  </code></pre>
  
  <p>i.e. each row shows the page's ancestors in the columns to the left, but there are different levels to the structure complicating matters.</p>
  
  <p>I'm trying to loop through this, starting in column 7 (the deepest level of navigation), and looping left initially to find a non-empty cell, and then copying that cell and its parent into my new sheet. Once it hits column 2 I want it to move down, as this contains the root; this carries on until the last row at 562.</p>
  
  <p>My code is below, but it's giving me an error on my 'While Isempty' line. What have I done wrong?</p>
  
  <pre><code>Sub directDescendent()
  
  Dim readCol As Integer
  Dim readRow As Integer
  Dim writeRow As Integer
  readCol = 7
  readRow = 2
  writeRow = 2
  
  While readRow &lt; 562
      While IsEmpty(ActiveWorkbook.Sheets(2).Cells(readRow, readCol).Value)
          readCol = readCol - 1
      Wend
      If readCol &lt; 3 Then
          readCol = 7
          readRow = readRow + 1
      End If
      ActiveWorkbook.Sheets(3).Cells(writeRow, 1).Value =     ActiveWorkbook.Sheets(2).Cells(readRow, readCol).Value
      ActiveWorkbook.Sheets(3).Cells(writeRow, 2).Value = ActiveWorkbook.Sheets(2).Cells(readRow, readCol - 1).Value
      writeRow = writeRow + 1
  
  Wend
  End Sub
  </code></pre>