+ Reply to Thread
Results 1 to 5 of 5

Assigning formulas using Range().Formula

  1. #1
    Registered User
    Join Date
    09-09-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Assigning formulas using Range().Formula

    Hi,

    I am quite new to VBA. I just started with a new macro of which a part is supposed to fill in formulas automatically in 3 loops. These formulas depend on several variables I created earlier. To assign these formules I found I had to use the code Range().Formula. The problem is that it doesn't work in the first 2 loops, but it does in the third. I did the same each time though (only different formules). I hope you can help me out here.

    Here some lines of code in a part that doesn't work:

    arr1 = celnaam1 & ":" & celnaam2
    arr2 = celnaam3 & ":" & celnaam4
    functie = "=" & celnaam & "*" & doelf & "-SOMPRODUCT(" & arr1 & ";" & arr2 & ")"
    ActiveCell.Offset(1, 0).Select
    Range(ActiveCell.Address).Formula = functie

    Regards,
    Jonas

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Assigning formulas using Range().Formula

    What does "doesn't work" exactly mean: error, wrong formula, no formula?

    When it "doesn't work", what is in the string variable functie ?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-09-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Assigning formulas using Range().Formula

    "Doesn't work" means that I get error message 1004. I can't make anything out of it. I already tried somewhat with adding quotation marks without much effect.

    When complete the string functie should contain (using an example where the other variables are filled in): =$A$2*Input!B5-SOMPRODUCT(Input!B5:Input!B10;A3:A8)

    It contains SOMPRODUCT, because I am Dutch-speaking and that is also the language in which I use Excel.

    I will try to attach the current file as well, if it might help. It also uses the Solver Add-In, if you want to try it.

    Regards,
    Jonas
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Assigning formulas using Range().Formula

    try using FormulaLocal

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    09-09-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Assigning formulas using Range().Formula

    Thaks! That FormulaLocal did the trick.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel Formula - assigning a # to a range
    By Josh1759 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-22-2013, 08:43 AM
  2. Replies: 8
    Last Post: 04-01-2012, 02:45 AM
  3. Assigning commonly used formulas a function name
    By The Phil in forum Excel General
    Replies: 3
    Last Post: 03-11-2010, 06:46 PM
  4. Assigning the range of a cell a value
    By jcarstens in forum Excel General
    Replies: 11
    Last Post: 05-06-2008, 08:22 PM
  5. Assigning set of range names
    By ADB in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-25-2005, 07:05 AM

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