View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Remove columns with all zeros

For a start you would be best off copying and pasting the macro as is to a
general module in the workbook to acted upon.

Otherwise you would have to qualify which workbook has the ActiveSheet.

UsedRange should take care of all columns and rows that Excel sees as being
in use on the active worksheet.


Gord Dibben MS Excel MVP

On Wed, 2 Jun 2010 15:28:24 -0700, Nora_GG
wrote:

Thank you Gary's Student. I am pretty new to building macros. I created the
macro below in a separate workbook and then opened it in the workbook I
needed to apply the macro. Should I have created the macro in the workbook
that needed the columns removed? Also, did I need to include a range in the
macro below or was it ok to copy as is? Appreciate the assistance.

"Gary''s Student" wrote:

Try this:

Sub RemoveColumns()
Dim nLastColumn As Long
Set r = ActiveSheet.UsedRange
nLastColumn = r.Columns.Count + r.Column - 1
For i = nLastColumn To 1 Step -1
If Application.WorksheetFunction.Sum(Columns(i)) = 0 Then
Columns(i).Delete
End If
Next
End Sub

--
Gary''s Student - gsnu201003


"Nora_GG" wrote:

How can I remove columns that contain all zeros? Is there a macro? I craeted
a sumif formula to flag columns subtotaling zero but I need a method to
remove these columns. Thanks