![]() |
delete cells containing zero after a cell containing a value
Try the below
Sub Macro() Dim lngCol As Long, lngLastCol As Long lngLastCol = ActiveSheet.Cells.Find(What:="*", _ SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column For lngCol = lngLastCol To 2 Step -1 If WorksheetFunction.CountIf(Columns(lngCol), "0") = 0 Then Columns(lngCol).ClearContents End If Next End Sub -- Jacob "Rupster" wrote: I have the following layout for several tabs. Mar-08 $0 $336 $4,808 $2036 $0 $0 $0 Apr-08 $0 $300 $130 $$0 $0 $0 May-08 $275 $433 $$0 $0 Jun-08 $25 $0 $0 Jul-08 $624 Each month data gets updated and the zeros all move one column to the right. I want to delete all the zeros after the cell containing a number. In the above example I want to delete all zeros after $2,036 in row 1.Is there a way I can delete them automatically without having to do it manually each month. |
delete cells containing zero after a cell containing a value
I can't see the OP's original message (actually, all I see is your
response), so I am using your message to post my reply. I think this single line of code will do what the OP wants... ActiveSheet.Cells.Replace 0, "", xlWhole -- Rick (MVP - Excel) "Jacob Skaria" wrote in message ... Try the below Sub Macro() Dim lngCol As Long, lngLastCol As Long lngLastCol = ActiveSheet.Cells.Find(What:="*", _ SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column For lngCol = lngLastCol To 2 Step -1 If WorksheetFunction.CountIf(Columns(lngCol), "0") = 0 Then Columns(lngCol).ClearContents End If Next End Sub -- Jacob "Rupster" wrote: I have the following layout for several tabs. Mar-08 $0 $336 $4,808 $2036 $0 $0 $0 Apr-08 $0 $300 $130 $$0 $0 $0 May-08 $275 $433 $$0 $0 Jun-08 $25 $0 $0 Jul-08 $624 Each month data gets updated and the zeros all move one column to the right. I want to delete all the zeros after the cell containing a number. In the above example I want to delete all zeros after $2,036 in row 1.Is there a way I can delete them automatically without having to do it manually each month. |
All times are GMT +1. The time now is 07:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com