+ Reply to Thread
Results 1 to 3 of 3

Convert Worksheet Function to Macro?

  1. #1
    Registered User
    Join Date
    09-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Convert Worksheet Function to Macro?

    I found this posting on another thread on this forum:

    =IF(COUNT(FIND(",",A2)),A2,LEFT(TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",99)),99))&", "&A2,LEN(A2)+1))

    which does exactly what I want it to do. Brilliant piece of logic!

    I added a little bit to it, to cover the formatting:

    =IF(COUNT(FIND(",",A1)),A1,LEFT(TRIM(UPPER(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))&", "&PROPER(A1),(LEN(A1)+1)))

    Is there a way to convert it to VBA (to place it in the worksheet change event), so that the end user can just type in the name John DOE, and have the macro flip it around to DOE, John?

    P.S. My first post. I hope I did it right......

    Thanks, all!
    Last edited by BadDogTitan; 09-16-2013 at 10:26 PM. Reason: Spelling.....

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Convert Worksheet Function to Macro?

    Hi,

    It's not a direct translation of the Excel formula to VBA, but it will produce the same result. Place this code into the Worksheet module (this code assumes that the user will type their name in Column A, from rows 2 onwards):
    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Convert Worksheet Function to Macro?

    Quote Originally Posted by BadDogTitan View Post
    Is there a way to convert it to VBA (to place it in the worksheet change event), so that the end user can just type in the name "John DOE," and have the macro flip it around to "DOE, John"?
    This will swap the data only if second word has comma at the end and is capable to hadle multiple entry.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Trying to Use a Convert function in a Macro
    By happyCal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 02:12 PM
  2. Convert a SUMPRODUCT function to a macro
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2013, 04:10 AM
  3. how to convert a macro to function
    By thpr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 05:18 AM
  4. convert iserror match function to macro
    By rooky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2010, 01:26 PM
  5. [SOLVED] Is there a macro or function to convert values to it written text
    By Dang Tran in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-19-2006, 06:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1