+ Reply to Thread
Results 1 to 6 of 6

Problem with pasting formula with VBA

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Question Problem with pasting formula with VBA

    Hi everyone,

    I have a sheet that is generated from data in another sheet with VBA.
    In this VBA I fill formulas into this generated sheet automatically.

    Now I need a new formula, and I have made one that works, but I struggle to fill it into the sheet with VBA.

    The formula is as follows:

    Please Login or Register  to view this content.
    This is exactly as how I made it when putting the formula together in the worksheet, after it has been created.
    Apologies for the norwegian function names. Here is a translation to English:
    • HVIS = IF
    • VENSTRE = LEFT
    • HØYRE = RIGHT
    • DELTEKST = MID

    The VBA is based on english function names, so I translated it, to the following:

    Please Login or Register  to view this content.
    This gives an error, with a compile error: Expected: end of statement. Probably due to the fact that I use "" inside the formula. What's the best way to do this, anyway?

    When changing this, so that I replace double with single quotes,
    Please Login or Register  to view this content.
    it throws a run-time error '1004': Application-defined or object-defined error.

    Then, since I'm not completely sure about using [@Object] to point to the column, so I change to the relative reference:
    Please Login or Register  to view this content.
    This throws the same error: run-time error '1004': Application-defined or object-defined error.

    For your reference - the source column is G and the destination column is I.

    This is the context I want to use the formula in:

    Please Login or Register  to view this content.
    Can somebody explain what I'm doing wrong? My head is going sore of all this thinking.

    Best regards,
    Knut
    Last edited by knutfh; 07-04-2013 at 06:35 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Problem with pasting formula with VBA

    Use double quote to put quotes inside a formula, for example:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Problem with pasting formula with VBA

    Quote Originally Posted by yudlugar View Post
    Use double quote to put quotes inside a formula, for example:
    Please Login or Register  to view this content.
    Thank you, yudlugar. That explains the first error, at least.

    I'm now trying the following code, but still get the 1004 run-time error.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Problem with pasting formula with VBA

    Try using commas instead of semi-colons, for example:
    Please Login or Register  to view this content.
    Seems to work when I tested it.

  5. #5
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Problem with pasting formula with VBA

    Quote Originally Posted by yudlugar View Post
    Try using commas instead of semi-colons, for example:
    Please Login or Register  to view this content.
    Seems to work when I tested it.
    GENIUS! That made the trick.
    Your help is really appreciated!

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Problem with pasting formula with VBA

    No problem

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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