+ Reply to Thread
Results 1 to 4 of 4

Proper syntax with formula in VBA

  1. #1
    Registered User
    Join Date
    06-08-2005
    MS-Off Ver
    Office 2010
    Posts
    37

    Proper syntax with formula in VBA

    This is a line from a VMA module I use.

    It's failing because I am not entering the concatenate properly and I'm not sure what the syntax should be.

    Please Login or Register  to view this content.
    The part of the code that's failing is where I am trying to concatenate "000" and the contents of 2. It would look like 0001234567.

    Thank you...This is the first time I've tried to concatenate in VBA.

    Ken
    Last edited by kcleere; 09-06-2012 at 10:45 AM.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Proper syntax with formula in VBA

    Couple of things wrong.

    First, your formula has two "(" and three ")", so that will fail.

    Second, as you are experiencing, there is a trick to adding " within a string. The trick is to use ""

    So,
    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-06-2012 at 10:27 AM. Reason: Please use code tags
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Proper syntax with formula in VBA

    Hi

    Range("C2:C" & last_row).Formula = "=IF(LEN(K2)=10,K2,""000""&K2)"
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    06-08-2005
    MS-Off Ver
    Office 2010
    Posts
    37

    Re: Proper syntax with formula in VBA

    Thank you both....works perfectly now.

    Have a great day...

    Ken

+ 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