Solved Deleting columns once zero value is found

March 20, 2013 at 12:50:10
Specs: Windows XP
What is the macro code to delete columns found when the value is zero. For instance If cells a1, b1, and c1 have values of other than 0 but then cells d1, e1, f1 have values of 0, how can I get Excel to know to deleted columns D, E, and F?

See More: Deleting columns once zero value is found

Report •

March 20, 2013 at 14:50:47
✔ Best Answer
Try this in a backup copy of your workbook:

Sub DelCol()
'Determine last column with data in Row 1
 lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through Row 1 (Reverse Order)
  For colNum = lastCol To 1 Step -1
'Delete Column if Row 1 contains 0
   If Cells(1, colNum) = 0 Then
    Cells(1, colNum).EntireColumn.Delete
   End If
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question