+ Reply to Thread
Results 1 to 7 of 7

Using a macro to put a function in a certain cell (runtime error 1004)

  1. #1
    Registered User
    Join Date
    10-17-2007
    Posts
    62

    Using a macro to put a function in a certain cell (runtime error 1004)

    Hi all,

    I have problems using a macro to define the function of let's say cell A5.

    I want to put the following function in the cell A5. I have tested this function itself and it works

    =IF(ISERROR(VLOOKUP($A4;INDIRECT($C$3);1;FALSE));" ";VLOOKUP($A4;INDIRECT($C$3&"2");2;FALSE))

    I use the following macro, but I get the runtime error 1004 (Application-defined or object defined error)

    Please Login or Register  to view this content.
    I really don't understand what I'm doing wrong

    Thank you all,
    -Juhanen-

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Try

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    10-17-2007
    Posts
    62
    Hi,

    Still the same error

    Thank you anyway,

    -Juhanen-

  4. #4
    Registered User
    Join Date
    10-17-2007
    Posts
    62
    I'm still struggling with the same problem. Now it seems that the problem is to use a macro to put an IF function to certain cell. Let me explain this via couple simplified examples:

    If I use for example this code it works

    Please Login or Register  to view this content.
    ...but this one doesn't (I have changed the SUM function to IF function)

    Please Login or Register  to view this content.
    So now I have no clue why is this..

    Thank you all,
    -Juhanen-

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try entering the formula as normal in a cell. Then turn on the macro recorder and enter a ' in front of the equals. Then view the recorded code will look like

    Please Login or Register  to view this content.
    then remove the R1C1 ref and remove the ' e.g

    Please Login or Register  to view this content.
    VBA Noob

  6. #6
    Registered User
    Join Date
    10-17-2007
    Posts
    62
    Now it works,

    For some reason I was forced to use FunctionR1C1 instead of Function though, so just had to record and trim it a bit.

    Anyways, thank you VBA noob, without your help i would still be hitting my head against the wall.

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    No problem. Glad it helped

    VBA Noob

+ 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