Delete column where a Zero appears in same row as Total

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have text total in Col A


I need a macro that where there is a zero in the same row as "total" in Col A , then all the columns containing the zero in the same row as Total to be deleted



Your assistance in this regard is most appreciated
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Is Total mentioned more than once in Column A?
How many Columns out are you looking for 0?
 
Last edited:
Upvote 0
The Total appears only once in Col A

There could be between 1 and 15 columns which sums up to zero-see sampole data below


Book1
ABCDEFGHIJKLM
12155511523005.62985115-23005.61215
22159995274770.2-241027684-0.02250-33743.71028.48
321692-210-2224292287392203.42241027-16690.0295-8513.01239243
421894-174867-460-216468365262.34-459.98
5Total0-222429526514.82203.420-174867000-21646830241026.5
Sheet1
Cell Formulas
RangeFormula
M1=SUM(B1:L1)
 
Upvote 0
How about
Code:
Sub DelZero()
   Dim i As Long
   Dim Fnd As Range
   
   Set Fnd = Range("A:A").Find("Total", , , xlWhole, , , False, , False)
   If Fnd Is Nothing Then Exit Sub
   For i = Cells(Fnd.row, Columns.Count).End(xlToLeft).Column To 2 Step -1
      If Cells(Fnd.row, i).Value = 0 Then Columns(i).Delete
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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