Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
VH VH is offline
external usenet poster
 
Posts: 13
Default How to search for zero in sheet

I want to delete zeroes at the end of a column. I want to delete everyone
except one. I have several columns with between 500 to 2000 rows. At the end
of each column there are several zeroes. I want to delete and keep only one
of them to shorten the number of rows. The sheet looks something like this:

A B C D E F
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 2 3 1 2 4
2 5 5 5 5 5
4 2 3 2 2 5
2 2 5 2 3 2
2 3 1 2 2 5
5 8 2 1 1 6
3 5 1 2 2 2
2 1 2 8 2 1
1 2 1 5 5 2
0 2 5 2 2 0
0 5 2 0 0 0
0 0 2 0 0 0
0 0 0 0 0 0
0 0 0 0 0
0 0
0 0

I do not want to delete the zeroes at the beginning of every column. Just at
the end. It is also important that the macro do not delete all of the zeroes.
I want one of them to stay at the end of the row.
Can anyone help me?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How to search for zero in sheet

Hi,
Try this:

With Worksheets("Sheet1")
For c = 1 To 6
LastRow = .Cells(Rows.Count, c).End(xlUp).Row
For r = LastRow To 1 Step -1
If .Cells(r - 1, c) = 0 Then
.Cells(r, c).Delete shift:=xlUp
Else
Exit For
End If
Next r
Next c
End With

"VH" wrote:

I want to delete zeroes at the end of a column. I want to delete everyone
except one. I have several columns with between 500 to 2000 rows. At the end
of each column there are several zeroes. I want to delete and keep only one
of them to shorten the number of rows. The sheet looks something like this:

A B C D E F
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 2 3 1 2 4
2 5 5 5 5 5
4 2 3 2 2 5
2 2 5 2 3 2
2 3 1 2 2 5
5 8 2 1 1 6
3 5 1 2 2 2
2 1 2 8 2 1
1 2 1 5 5 2
0 2 5 2 2 0
0 5 2 0 0 0
0 0 2 0 0 0
0 0 0 0 0 0
0 0 0 0 0
0 0
0 0

I do not want to delete the zeroes at the beginning of every column. Just at
the end. It is also important that the macro do not delete all of the zeroes.
I want one of them to stay at the end of the row.
Can anyone help me?

  #3   Report Post  
Posted to microsoft.public.excel.programming
VH VH is offline
external usenet poster
 
Posts: 13
Default How to search for zero in sheet

Thank you very much! Works great!

Toppers skrev:

Hi,
Try this:

With Worksheets("Sheet1")
For c = 1 To 6
LastRow = .Cells(Rows.Count, c).End(xlUp).Row
For r = LastRow To 1 Step -1
If .Cells(r - 1, c) = 0 Then
.Cells(r, c).Delete shift:=xlUp
Else
Exit For
End If
Next r
Next c
End With

"VH" wrote:

I want to delete zeroes at the end of a column. I want to delete everyone
except one. I have several columns with between 500 to 2000 rows. At the end
of each column there are several zeroes. I want to delete and keep only one
of them to shorten the number of rows. The sheet looks something like this:

A B C D E F
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1 2 3 1 2 4
2 5 5 5 5 5
4 2 3 2 2 5
2 2 5 2 3 2
2 3 1 2 2 5
5 8 2 1 1 6
3 5 1 2 2 2
2 1 2 8 2 1
1 2 1 5 5 2
0 2 5 2 2 0
0 5 2 0 0 0
0 0 2 0 0 0
0 0 0 0 0 0
0 0 0 0 0
0 0
0 0

I do not want to delete the zeroes at the beginning of every column. Just at
the end. It is also important that the macro do not delete all of the zeroes.
I want one of them to stay at the end of the row.
Can anyone help me?

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
Search a name in one sheet and entry it into another sheet Shilpi Excel Worksheet Functions 4 May 5th 09 01:11 AM
search a value in W/sheet TUNGANA KURMA RAJU Excel Discussion (Misc queries) 7 April 4th 09 01:54 AM
Search for rows in one sheet and copy into another sheet based on customer id [email protected] Excel Worksheet Functions 1 October 22nd 07 03:09 AM
Search for a Sheet Chance224 Excel Discussion (Misc queries) 3 December 14th 04 12:29 AM
search for a sheet Lee S.[_3_] Excel Programming 1 September 13th 03 01:55 AM


All times are GMT +1. The time now is 01:11 AM.

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

About Us

"It's about Microsoft Excel"