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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
When deleting columns, one should work from right to left.
Code:
For Col = (NumCusips+3) To 4  Step -1
 
Upvote 0

Forum statistics

Threads
1,214,889
Messages
6,122,097
Members
449,065
Latest member
albertocarrillom

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
Back
Top