+ Reply to Thread
Results 1 to 4 of 4

Using Excel function in VB code

  1. #1
    Forum Contributor vandanavai's Avatar
    Join Date
    09-04-2006
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Using Excel function in VB code

    I am trying to use below mentioned formula in VB code. This code first activates sheet called as "Debtor". Formula is to be put in Range A2:A5000 in sheet "Debtor". Formula refers to certain cells in sheet called "Register". However it is not working. Run time error1004 and application or object defined error occurs. But same formula works if directly entered in worksheet.
    What is the mistake?

    Range("A5.A5000").Formula = "=IF(ISNA(VLOOKUP($A$1&ROW()-4,Register!$A:$L,4,FALSE)),"",(VLOOKUP($A$1&ROW()-4,Register!$A:$L,4,FALSE)))"


    Please help me.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Presumably the Debtor worksheet isn't protected?
    Martin

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon vandanavai

    The problem here lies in the fact that you are including a set of quotes in the formula - Excel thinks that the first set signifies the end of a string and the second set signifies the start of another, and consequently the formula gets confused when you attempt to post it.

    Range("A5.A5000").Formula = "=IF(ISNA(VLOOKUP($A$1&ROW()-4,Register!$A:$L,4,FALSE)),"",(VLOOKUP($A$1&ROW()-4,Register!$A:$L,4,FALSE)))"

    So what we need to do is remove them and replace them with the ASCII code for a quote (34) to force them into the formula that way, thus :

    Please Login or Register  to view this content.
    HTH

    DominicB

    Edit : Correct typo
    Please familiarise yourself with the rules before posting. You can find them here.

  4. #4
    Forum Contributor vandanavai's Avatar
    Join Date
    09-04-2006
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256
    Thanks a lot DominicB.
    It worked perfectly.

+ 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