PDA

View Full Version : Delete Columns if value equals zero



f2e4
11-27-2007, 04:01 PM
Hi guys,

I am using the following code to delete rows if the values in column Z = 0


Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 5
Lastrow = 466
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "Z")
If Not IsError(.Value) Then
If .Value = 0 Then .EntireRow.Delete
End If
End With
Next Lrow
End With


I am now have a table of values from columns B to W

I was wondering if it is possible to modify the above code or even get help with a new code that will do the following:


Find the last row of values (must have this as the no.of rows varys depends on much data is produced)
If any of the values in this row equal zero, then to delete that columnAs always, your help is greatly appreciated

Bob Phillips
11-27-2007, 04:13 PM
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
Firstrow = 5
Lastrow = 466
For Lrow = Lastrow To Firstrow Step -1
If Application.CountIf(.Rows(i), 0) > 0 Then
.Rows(i).Delete
End If
Next Lrow
End With

f2e4
11-27-2007, 04:32 PM
Thanks for the help xld but forgot put an important point in my last message

Is there a way to create a row at the end of my table which has the sums of each column from B to W

But again, the number of rows will always vary so cannot be set

Then from this row - if the sum = 0, then delete that column