Delete Columns Where a cell sums to zero

mpeters102

New Member
Joined
Mar 14, 2009
Messages
10
Hello All,

This is my first post so If I am missing any details please let me know.

I have a spreadsheet where I sum the total of all the rows below a certain cell, I do so for about 80 columns. I would like to write a marco which deletes the entire column if that sum = 0

I have the below written, but it does not work in every circumstance it seems to pick random columns to delete...I need a better way to do this please help!!

Dim Cusips As Range
Dim NumCusips As Integer
Dim Col As Integer


Sheets("Corp").Select
Range("FirstCorpCell").Select
Range(Selection, Selection.End(xlToRight)).Select

Set Cusips = Selection
NumCusips = Cusips.Count


For Col = 4 To (NumCusips + 3) Step 1

If Cells(9, Col).Value < 1 Then Columns(Col).EntireColumn.Delete

Next Col
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,958
When deleting columns, one should work from right to left.
Code:
For Col = (NumCusips+3) To 4  Step -1
 

Watch MrExcel Video

Forum statistics

Threads
1,127,465
Messages
5,624,902
Members
416,064
Latest member
PaulBr2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top