Delete Columns based on a condition

  • Thread starter Thread starter Joel Mills
  • Start date Start date
J

Joel Mills

I would like to be able to delete columns in the Active Spreadsheed based on
cells in a Range (B2:IV2), where any cells containing #Value! or Grand
Total would result in the column being deleted. I am using Excel 2000.

Joel
 
Joel,

You could do a macro:

Sub DeleteColumns()
Dim i As Integer

For i = 256 To 1 Step -1
If Cells(1, i).Text = "#VALUE!" Or _
Cells(1, i).Text = "Grand Total" Then
Cells(1, i).EntireColumn.Delete
End If
Next i
End Sub

HTH,
Bernie
MS Excel MVP
 
Sub testerBBB()
Dim rng As Range, rng1 As Range
On Error Resume Next
Set rng = Range("B2:IV2").SpecialCells(xlFormulas, xlErrors)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireColumn.Delete
Do
Set rng1 = Range("B2:IV2").Find("Grand Total", _
Lookat:=xlPart)
If rng1 Is Nothing Then Exit Do
rng1.EntireColumn.Delete
Loop While True

End Sub
 
Thanks Tom this work perfectly.

Tom Ogilvy said:
Sub testerBBB()
Dim rng As Range, rng1 As Range
On Error Resume Next
Set rng = Range("B2:IV2").SpecialCells(xlFormulas, xlErrors)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireColumn.Delete
Do
Set rng1 = Range("B2:IV2").Find("Grand Total", _
Lookat:=xlPart)
If rng1 Is Nothing Then Exit Do
rng1.EntireColumn.Delete
Loop While True

End Sub

--
Regards,
Tom Ogilvy




based
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top