View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default Delete rightmost zeroes

On Tue, 27 Sep 2011 02:28:21 -0700 (PDT), gcotterl wrote:

How can I delete all of the zeroes to the right of the last 9 in each
row?

For example, here are some rows:

0000000000000000000009990000000
0000000099099000000000000000000
9999000000000000000000000000000
0000000000000000000000000099900
0000000000000099999990000000000
0900000000000000000000000000000
0000000000000000099999000000000

This is result I'm looking for:

000000000000000000000999
0000000099099
9999
00000000000000000000000000999
000000000000009999999
09
0000000000000000099999



Assuming by "row" you mean "cell"

You can do this with a worksheet formula also:

If your data starts in A1, then:

B2: =LEFT(A1,LOOKUP(2,1/(MID(A1,ROW(INDIRECT("1:99")),1)="9"),ROW(INDIRECT ("1:99"))))

and fill down as far as required. Just make sure the "99" is at least as long as the longest string in the sequence.



Then, how do I find the longest row?


If your above formula results are in, for example, B1:B7, then:

This formula must be **array-entered**:

=MATCH(MAX(LEN(B1:B7)),LEN(B1:B7),0)

----------------------------------------

To **array-enter** a formula, after entering
the formula into the cell or formula bar, hold down
<ctrl<shift while hitting <enter. If you did this
correctly, Excel will place braces {...} around the formula.