adding a character

  • Thread starter enrico via OfficeKB.com
  • Start date
E

enrico via OfficeKB.com

how do i create a condition on a particular cell if it's characters are less
than 8 it will add a character? e.g. if i put "abcdefg" in my cell, there are
only 7 characters in it. the other cell will automatically add a new 1 before
the original character so it will become "zabcdefg" which "z" is the
character added to make it 8
 
D

Dave Peterson

And if it were only 1 character, you'd end up with:
zzzzzzza

And if it were empty, leave it empty?
=if(a1="","",right(rept("z",8)&a1,8))

This will actually truncate the string at 8 characters. If the original had
1000 characters, the formula will result in the 8 rightmost.
 
E

enrico via OfficeKB.com

what if there are a lot of characters? i don't want to truncate the other
values. all i want is if my variable inside the cell is less than 8
characters then it will add another one to make it 8
 
R

Ron Rosenfeld

how do i create a condition on a particular cell if it's characters are less
than 8 it will add a character? e.g. if i put "abcdefg" in my cell, there are
only 7 characters in it. the other cell will automatically add a new 1 before
the original character so it will become "zabcdefg" which "z" is the
character added to make it 8

Maybe:

=REPT("z",MAX(0,8-LEN(A1)))&A1

--ron
 
D

Dave Peterson

Just add another check:

=IF(A1="","",IF(LEN(A1)>8,A1,RIGHT(REPT("z",8)&A1,8)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top