ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Columns based on a condition (https://www.excelbanter.com/excel-programming/306246-delete-columns-based-condition.html)

Joel Mills

Delete Columns based on a condition
 
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



Bernie Deitrick

Delete Columns based on a condition
 
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

"Joel Mills" wrote in message
...
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





Tom Ogilvy

Delete Columns based on a condition
 
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




"Joel Mills" wrote in message
...
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 Mills

Delete Columns based on a condition
 
Thanks Tom this work perfectly.

"Tom Ogilvy" wrote in message
...
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




"Joel Mills" wrote in message
...
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








All times are GMT +1. The time now is 03:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com