I need to write a sub program that will add the first and last digits of a number. For example, for a number like 1234: I need the answer to be 5 (1+4).
Your help is highly appreciated.
Ben
I need to write a sub program that will add the first and last digits of a number. For example, for a number like 1234: I need the answer to be 5 (1+4).
Your help is highly appreciated.
Ben
Last edited by CollegeKidd; 02-13-2011 at 06:40 PM.
I guess this is your homework? What have you tried so far?
regards
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
I have no clue how to even separate the digits. In our lab we just covered the basics of writing a sub program. Didn't go over how to separate digits of anything. I have no clue on how to get started. Maybe define one variable as the first number, the second as the last then just add the variables. I just don't know how to separate them.
Last edited by CollegeKidd; 02-13-2011 at 06:19 PM.
This is Excel. Do you need a program or can you just use a formula?
If you're using a formula, look at LEFT and RIGHT to getthe digits and SUM, or just a plus sign (+) to add them together.
If you need a "sub program", you'd use the same approach. Define a variable, put 1234 in it, use LEFT to get the first digit and RIGHT to get the last digit. Add them together in another variable and do something with it ... maybe a Msgbox.
Come back if you get stuck ... or to say thanks for pointing you in the right direction ;-)
Regards
The left-right thing worked!!!! I didn't know how to separate them thanks. I just had it output it to cell and get the input from another cell. That is the way my assignment told me to do it.
Ben
You're welcome. Thanks for the feedback. It's good to "hear" the sense of achievement.
Regards
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks