In case it wasn't obvious: In spite of my longevity in programming, trying to squeeze productive logic out of a single Excel cell was not something that just rolled off my tongue. At one time or another, it was true of different languages, including COBOL, FORTRAN,PL/1, BASIC, assembly languages, and machine language (yes, I keyed programs into a CDC 160A by pressing bit buttons on the console) and others. But this little trick you pulled on us was quite the challenge for me. I worked many hours on it, and enjoyed every minute! Thank you!
While I worked on it though, it really bugged me that I was making the machine do the same thing every time I needed something, e.g., find the position of the first space, when if I had been working in VBA, I would have been able to find it once and store its value, so that the next time I needed it, it was sitting there waiting for me to grab it. That's only one example of how awkward cell work can be, in spite of the fabulous power that Excel has to get things done that I wouldn't want to do in VBA. But if you know VBA (and if you don't, it's easy to learn) there is something you should be aware of.
You can code a function in VBA to do something, say extract a middle initial, using all the efficiencies that VBA provides, give it a name like GetMI, and then simply call that function from your Excel cell like any other function: =GetMI. You can set up the function to receive parameters that make it even more powerful, like maybe giving it the number of the current row in an array of full names so that you could loop through the array to process all the names, using the same function each time, as in =GetMI(NameRow).
If I've piqued your interest, just Google "Call a VBA function from Excel" and see what shows up. Enjoy!
|