How do I capture the last character in a string inside a macro?

J

JasonK

Thanks in advance.

I've written a macro that will take data from my worksheet and compile
a report that I have to write often at work. The customer's name is
mentioned in the report several times, once in the possessive. I can
make the macro place a " 's " at the proper time, but I can't make it
not place it there when the customer's name ends in " s ". I need to
call the last character in the name string, called "LastName" and
determine if it's an " s " or not. Can someone please teach me how to
do that?

Also, I will end up sharing this spreadsheet with co-workers and I
don't want them to have access to the code. Not because I don't want
to share; I don't want them to wreck it. The spreadsheet will sit in a
directory on our computers that is common to all workers. I could just
save a copy and over write occasionally, but if there is a way to lock
the code, it would be easier for me.

Thanks guys and girls. I appreciate all the help. The thread on the
"Randomize Timer" was phenomenal. It helped me a great deal. When I
ran my dice program using Randomize Timer at the beginning of the
macro, and just using "RND" to "roll the dice", it lost the correct
amount of money within normal parameters.

JasonK
 
P

Paul Robinson

Hi
Text string issue
If Right(teststring,1)<>"s" then
teststring = teststring & "'s"
end if

will put 's on the end if teststring does not end in s.
To protect code in the VBEditor do Tools, VBAProjectProperties,
Protection and set a password.

regards
Paul
 

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