View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
patrick molloy patrick molloy is offline
external usenet poster
 
Posts: 391
Default TRICKY ONE FOR YOU CODEMASTERS!!!

I'm not clear where your text box is, but let's assume
that the text is in MyText

' first digit
SELECT CASE Left(MyText,1)
CASE "4"
MyText = "D/" & MID(MyText,2)
CASE "8"
MyText = "A/" & MID(MyText,2)
CASE "7"
MyText = "7/" & MID(MyText,2)
CASE ELSE
END SELECT
' now for the last digit
LastLeter = RIGHT(MyText,1)
MyText = Left(MyText,LEN(MyText)-1)
If LastLetter = "*" Then
LastLetter = "10"
End If
MyText = MyText & "-" & LastLetter


' MyText now contains your amended text
If its from a cell, then use the sheet's Change event to
run the code
If its from a form, then you could use an OK button to
check these text boxes...

HTH

Patrick Molloy
Microsoft Excel MVP



-----Original Message-----
A Challenge for you all, I desperately need help.

I would like code that will manipulate a number upon

entry
into a text box.

When entering a number eg 487654321 and pressing enter,

it
checks the 1st digit, and depending on the digit replces
it with a number, i.e a 4 is a D/, a 8 is a A/. But if

the
first digit is a 7 it keeps it as a 7/. Basically the
ability for me to define what the first digit will be
replaced with.

It also checks the last digit and puts a dash before it

so
ending in 1 becomes -1, ending in 4 becomes -4 apart

from
when it ends in * then I want it to become -10.

A few examples

4123456789 --- D/12345678-9
412345678* --- D/12345678-10
8876543210 --- A/87654321-0
7232323232 --- 7/23232323-2

Hope someone is bright enough to help

Thanks

Dean Knox
.