title: How to remove empty column with heading?
body: <p>I have column headings like Material 1, Material 2,... Material 15. Below these headings if there is no data i.e. if the column is empty. Then the entire column should be deleted automatically.</p>
  
  <p>Example : if the Material 5, Material 7, up to Material 15 columns are empty then they should be deleted.</p>
  
  <p>I was trying the below code, however its not working till Material 15 column it stops after deleting 2 or 3 columns. Kindly help me.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Sub clearcol()
  On Error Resume Next
   Dim lRealLastRow, lRealLastCol As Long
      lRealLastRow = Cells.Find("*", Range("A1"), xlValues, , xlByRows, xlPrevious).Row
      lRealLastCol = Cells.Find("*", Range("A1"), xlValues, , xlByColumns, xlPrevious).Column
      For i = 1 To lRealLastCol
          If lRealLastRow - WorksheetFunction.CountBlank(Intersect(Columns(i), ActiveSheet.UsedRange)) &lt;= 1 Then _
              Columns(i).EntireColumn.Delete
      Next i
  
  End Sub
   </code></pre>
  </div>
  </div>
  </p>