Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADD A BUTTON TO A CELL TO DELETE A RANGE OF CELLS? traveye Excel Discussion (Misc queries) 5 November 5th 07 12:57 PM
Delete cell shifts cells up - How to avaoid happening user2616 Excel Discussion (Misc queries) 0 October 23rd 07 06:51 PM
Delete record(s) in other cells based on value of one cell. MPope Excel Discussion (Misc queries) 1 October 12th 05 06:57 PM
Delete/clear a cell based on another cells contents jademaddy Excel Programming 2 May 19th 05 06:15 PM
How do you delete one cell from a range of protected cells Cgbilliar Excel Worksheet Functions 2 November 3rd 04 10:42 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"