+ Reply to Thread
Results 1 to 8 of 8

Inserting a formula into a cell using a macro

  1. #1
    Registered User
    Join Date
    10-30-2003
    Posts
    50

    Inserting a formula into a cell using a macro



    Hi Chaps,

    I have a spreadsheet which needs to be linked to another spreadsheet.

    I have written a macro to insert all the links from one sheet to another when you add a new line.

    Most of it is just cell refs but there are some formula too.

    Here is some of the code I currently have:

    ActiveCell.Offset(0, 26).Value = "=(IF(AU3="G","Green",IF(AU3="A","Amber",IF(AU3="H","On Hold","Red"))))"

    I would like to stick to the A1 notation rather than the R1C1 and I would like the formula inserted as the value of the cells will change.

    TIA,

    Lou


  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Use the instruction
    Please Login or Register  to view this content.
    HTH
    Carim


    Top Excel Links

  3. #3
    Registered User
    Join Date
    10-30-2003
    Posts
    50

    Thanks!

    Hi Carim,

    Thanks for the prompt response!

    I need to use the activecell.offset as i found this easier than moving the activecell and having to select it and then define the value and then move again!

    Is there anyway of combining the .formula with the offset function?

    TIA,

    MoonWeazel

  4. #4
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Yes ...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-30-2003
    Posts
    50

    Excellent....still got a bit of a problem!!!

    Hi Carim,

    Thanks again!

    When I entered the line...

    =IF(AU4="G","Green",IF(AU4="A","Amber",IF(AU4="H","On Hold","Red")))

    I get a syntax error message and a compile error with the "G" highlighted.

    Any helps is very groovily accepted!!!

    Ta!

    MW

  6. #6
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi again,

    For quotes to appear, you need to double them ...
    i.e. ""...""

  7. #7
    Registered User
    Join Date
    10-30-2003
    Posts
    50

    so sorry!

    am being a bit thick!!!

    i have done as you suggested but it is still coughing up errors!

    now i get an expected expression error:

    here is the line of code:

    Activecell.Offset(0,26).Formula = ""=IF(AU4="G","Green",IF(AU4="A","Amber",IF(AU4="H","On Hold","Red")))""

    please help - i think that i am getting a headache from staring at the screen for hours!

    MW

  8. #8
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi again ...

    Should have explained better ...

    Please Login or Register  to view this content.

+ 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