+ Reply to Thread
Results 1 to 3 of 3

Need help inserting formula with VBA

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Need help inserting formula with VBA

    I have a formula I'm trying to insert with VBA, but I keep getting a compile error. The formula is looking for blank spaces between words, and the VB editor keeps saying there is a compile error and highlights the area of my formula that has " ". Here is the formula I'm trying to insert with VBA:

    =IF(A2="","",IF((LEN(A2)-LEN(SUBSTITUTE(A2," ",""))<=1),A2,(LEFT(A2,FIND(" ",A2,FIND(" ",A2,1)+1)-1))))

    When I put this in the cell manually, it works fine. But I cannot insert it using VBA. Here's my VBA line:

    Please Login or Register  to view this content.
    Here's where I'm getting hit with an error:

    Please Login or Register  to view this content.
    It says End of Statement Expected.

    I've tried recording a macro while entering this formula, but that doesn't work either. Here's what the recorder gave me:
    Please Login or Register  to view this content.
    As you can see, it's R1C1 format. When I tried using the above in my code, it did put the formulas in the cells, however, it replaced column A with column BDF...which is far from correct. Any suggestions?

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

    Re: Need help inserting formula with VBA

    Try this.
    Please Login or Register  to view this content.
    By the way, you could get that by doing a find and replace on the R1C1 formula, finding R[-1]C[-2] and replacing with A2, oh and you'd have to change to Formula.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Need help inserting formula with VBA

    Wow, Norie. You're great! Really, you are always so helpful and are a wealth of knowledge. I appreciate it. This is solved!

+ 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. inserting formula into vba
    By mesi1769 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2011, 09:47 AM
  2. inserting formula
    By enyaw in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-08-2006, 10:55 AM
  3. [SOLVED] inserting formula
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-27-2006, 10:00 AM
  4. HELP with inserting formula
    By Dragos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2005, 11:05 AM
  5. [SOLVED] inserting a formula
    By dstiefe in forum Excel General
    Replies: 6
    Last Post: 08-10-2005, 05:05 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