changing text in a formula

W

wendy

Ok, I hope this doesn't sound to confusing. I need a
formula that changes the text in one cell to a different
text in another cell leaving the last 4 digits the same.
This is for credit card numbers so here is what I'm
looking to do:

cell b14 has a credit card number in it of 123456789
in cell B25 I need it to read as XXXXX6789

Is this possible?
 
D

Dan E

Wendy,

If the length of the numbers is constant

="XXXXX" & RIGHT(A1,4)

If the length changes

=REPT("X",LEN(D13)-4) & RIGHT(D13,4)

Dan E
 
D

Don Guillett

Will this work?
Sub lastfour()
For Each c In Selection
c.Value = "xxxxx" & Right(c, 4)
Next
End Sub
 
G

Guest

Dan:

Thanks for the help, it worked. But...now I have another
dilema - if there is no cc number in field B14, Field B25
is now showing # value. How do we get B25 to remain
blank if no cc number is entered in B14?

Thanks,
Wendy
 
D

Dan E

Wendy,

=IF(B14<>"",REPT("X",LEN(B14)-4) & RIGHT(B14,4),"")

So if B14 is blank ("") B25 (where this formula is) will also
be blank.

OR

=IF(ISERR(REPT("X",LEN(B14)-4) & RIGHT(B14,4)),"",REPT("X",LEN(B14)-4) & RIGHT(B14,4))

So if the formula evaluates to an error the cell is left blank.

Dan E
 

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