+ Reply to Thread
Results 1 to 6 of 6

Convert Excel Formula to Macro Code

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Convert Excel Formula to Macro Code

    I received assistance from NBVC for combining data from two cells. Post https://www.excelforum.com/showthread.php?p=2135144. I need to convert the formula into macro code. I thought I would be able to convert it on my own, but running into some troubles with run time errors.

    Here is the Excel formula, which is working fine.
    Please Login or Register  to view this content.
    .Here is what I am trying for the macro
    Please Login or Register  to view this content.
    Last edited by maacmaac; 07-28-2009 at 10:14 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,997

    Re: Convert Excel Formula to Macro Code

    Why is that dot in front of Cells? Is that line part of a With..End With block?
    Ben Van Johnson

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Convert Excel Formula to Macro Code

    Hello maacmaac,

    This macro will join the date using the data in column "A" and "B" of the active sheet. It starts in cell "A2" and continues down to the last entry in column "A". The macro uses advanced pattern recognition to parse and merge the strings in the adjacent cell in column "C". If the pattern is not recognized then the cell in column "C' is left blank. This is much faster and flexible than using string manipulation to achieve the same results.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: Convert Excel Formula to Macro Code

    Leith,

    Thanks for the code. I can't seem to get it working for all the scenarios. It appears to only be returning a value in column C only if the month and day in column A is equal.

    I have attached a sample for viewing. The expected result is in column E. Thanks again for your assistance.
    Attached Files Attached Files

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Convert Excel Formula to Macro Code

    Hello maacmaac,

    My mistake. I am still learning the nuances of this. I changed the first pattern. The way I had it written it was only matching when the month and day were the same. That has been fixed. The macro nelow has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: Convert Excel Formula to Macro Code

    Leith,

    That did the trick. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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