+ Reply to Thread
Results 1 to 4 of 4

Translating excel formula into VBA - remove characters after last comma.

  1. #1
    Registered User
    Join Date
    10-13-2012
    Location
    Cali
    MS-Off Ver
    Excel 2003
    Posts
    22

    Translating excel formula into VBA - remove characters after last comma.

    Hello,

    I have some code that works in excel but I am trying to get the formula into VBA - I am getting a compile error for invalid character on the "@". The values are in column A and would be output in column B of sheet2. Any help would be great.

    Here is the excel formula that works:

    =IFERROR(LEFT(A1,FIND("@",SUBSTITUTE(A1,",","@",LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))-1),"")

    Below is what I am trying with VBA:

    Set calcsheet = Sheets("sheet2")
    With calcsheet.Range("b1:B100000")
    .FormulaR1C1 = _
    "=Left(RC1, Find("@", Substitute(RC1, ",", "@", Len(RC1) - Len(Substitute(RC1, ",", "")))) - 1)"
    .Value = .Value
    End With

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Translating excel formula into VBA - remove characters after last comma.

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,701

    Re: Translating excel formula into VBA - remove characters after last comma.

    For future reference:
    Enter the formula in a cell
    Select the cell
    Following depends on Excel Version but you get the idea.
    Tools, Macro, Record (Yes to Macro Name)
    F2, Enter
    Your formula is now in VBA format as code. (Check it!)

    Just for the heck of it, without a formula.
    Might be considerably slower because of the looping. Let us know if you try it.
    Please Login or Register  to view this content.
    Last edited by jolivanes; 04-06-2016 at 01:15 AM. Reason: Add code

  4. #4
    Registered User
    Join Date
    10-13-2012
    Location
    Cali
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Translating excel formula into VBA - remove characters after last comma.

    Hello all, thank you for the posts! I didn't try the loop since I have almost a million rows of data, it runs pretty quick using the excel formulas. Thanks again!

+ 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. Formula to remove the comma sign at end of names
    By zicitron in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-15-2013, 05:55 AM
  2. Find and remove all text to the left of last comma (including comma) in a cell
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2013, 08:47 AM
  3. [SOLVED] Formula needed for Removing Certain word + characters up to next Comma in a Cell
    By alw99 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-03-2012, 11:07 AM
  4. Formula to remove entries after comma
    By Damian84 in forum Excel General
    Replies: 4
    Last Post: 03-16-2012, 09:43 AM
  5. How can I prevent Non English characters from translating to question marks
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2012, 12:53 PM
  6. translating a formula into Excel 97-2003
    By exced in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-29-2008, 10:29 PM
  7. [SOLVED] Translating an IF formula from Lotus 1-2-3 to Excel
    By fsufan13 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-03-2005, 08:40 PM
  8. [SOLVED] Translating an IF formula from Lotus 1-2-3 to Excel
    By fsufan13 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-02-2005, 06:17 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