+ Reply to Thread
Results 1 to 6 of 6

Got a formula I would like to change into a macro.

  1. #1
    Registered User
    Join Date
    10-18-2012
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    29

    Got a formula I would like to change into a macro.

    So I got this formula that will look at a cell and delete the last string of characters after the last space.

    =LEFT(B2,FIND("|",SUBSTITUTE(B2," ","|",LEN(B2)-LEN(SUBSTITUTE(B2," ",""))))-1)

    I don't completely understand as in how it's doing it, but I would like to write a macro to produce the result in Cell B2 and consecutive rows in Column B.

    Any insight would be greatly appreciated.

    Thanks

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,534

    Re: Got a formula I would like to change into a macro.

    Like this:
    Please Login or Register  to view this content.
    Artik

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Got a formula I would like to change into a macro.

    tripey,

    Welcome to the forum!
    Here's an alternate method that puts the result as a value into the cells in column B directly:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    10-18-2012
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Got a formula I would like to change into a macro.

    Awesome! I'm gonna check these out.

  5. #5
    Registered User
    Join Date
    10-18-2012
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Got a formula I would like to change into a macro.

    @ tigeravatar

    I couldn't get your code to work tiger, when I ran it... I ended with some cells that had #VALUE! in them. I ended up using Artik's code and then cut and paste into column B. The excel file is done but I'm curious to see if I can get this to work with tiger's code.

    From what I can understand:

    This is dictating which column in the range. Count the rows in B? End(xlUp) - Does this mean going up from the end of counted rows?
    Please Login or Register  to view this content.
    Not sure about this next one at all.
    Range.Value = Evaluate the Index starting from the left? and the Range.Address? (Tried googling Address, don't know what this is), and FIND the cell border line "|".
    Substitute whatever Range.Address is with (","" "", <---- Not sure what is this. Spaces?) and "|" cell border line, Length of characters in Cell Column B .Row MINUS Length of ... uh I don't know.. Whatever that was Substituted and the .Address and spaces MINUS 1 space at the end.
    Please Login or Register  to view this content.
    I kind of get it, but as you can see... not really. Heh. I'd like to be able to dissect and completely understand it so I can try to write some code myself.

    Any insight would be greatly appreciated
    Last edited by Cutter; 10-22-2012 at 09:09 AM. Reason: Removed whole post quote

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Got a formula I would like to change into a macro.

    tripey,

    When I tested the code, it ran just fine on my test file. I'd have to see an example file that is experiencing the problem.
    As for the Evalue method, all it does is interpret a text string as if it were an Excel Formula. The .Address is a replacement for the cell reference B2 from your original post, but other than that, it uses the exact formula you provided in your original post. .Address just makes it so that it works on the defined range instead of just 1 cell.

+ 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