View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.newusers
Shane Devenshire[_2_] Shane Devenshire[_2_] is offline
external usenet poster
 
Posts: 3,346
Default delete columns if 0

Hi,

Here is code to delete all rows which have blank cells in column A. You can
modify this to delete all cells of many different types and for any column.

Sub DeleteRows()
Range("A1:A" &
Range("A65536").End(xlUp).Row).SpecialCells(xlCell TypeBlanks).EntireRow.Delete
End Sub

Similar code for deleting Columns that all contain formulas which evaluate
to numbers on row 2 would look like this:

Sub DeleteColumns()
Range("B2:" &
[IV2].End(xlToLeft).Address).SpecialCells(xlCellTypeFor mulas,
1).EntireColumn.Delete
End Sub

And the code to address your specific example:

Sub DeleteIfZero()
With Range("B1:B" & [B65536].End(xlUp).Row)
Set c = .Find(0, LookIn:=xlValues)
If Not c Is Nothing Then
[A:G].Delete
End If
End With
End Sub

Note as asked you want to delete the entire columns A:G if any cell in
column B contains 0. I'm not sure that my interpretation of your problem is
correct.

If this helps, please click the Yes button

Cheers,
Shane Devenshire

"jatman" wrote:

i am using the following code to delete the complete row:

Range("B:B").Select
Selection.AutoFilter Field:=1, Criteria1:="0"
On Error GoTo line1
With Sheet1.Range("b:b")
Cells.SpecialCells(xlCellTypeVisible).EntireRow.De lete
End With
line1:

what i need is to delete only columns a:g (not the entire row) if the value
in column b = 0.

any help is appreciated.

jat