+ Reply to Thread
Results 1 to 9 of 9

Add formula to multible cells !

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Add formula to multible cells !

    Hi this one feels it should be easy but im going cracy here.

    I have a overview page and when i press a button i want formulas to be added to specific cell.
    Im using this code to add the formula to the cell:
    [A1].FormulaLocal = "=SUMMA(Sheet2!A1)"
    When i press the button i want the code to add it to Range A1:A1000
    and to save me some time i wonder if its any way to add it directly to the range and not like this:
    [A1].FormulaLocal = "=SUMMA(Sheet2!A1)"
    [A2].FormulaLocal = "=SUMMA(Sheet2!A2)"
    [A3].FormulaLocal = "=SUMMA(Sheet2!A3)"
    Etc.
    I know how to add the formula to a range of cells but in this case the range in the formula has to change
    as above.

    Petter
    Last edited by Petter120; 03-05-2012 at 06:44 PM.

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Add formula to multible cells !

    try this
    Sub aa()
    Dim x As Long
    For x = 1 To 1000
    Cells(x, 1).FormulaLocal = "=SUMMA(Sheet2!A" & x & ")"
    Next
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Re: Add formula to multible cells !

    It works perfect A follow up question is there anyway to get the code above to only add the formula if there is a value in the cell on sheet2.

    Lets say only if theres a value in Sheet2 A1:A10 it feels unnecessary to copy the formula to 1000 row ?

    Petter

  4. #4
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Add formula to multible cells !

    Could you send the small sample of wokrbook?

  5. #5
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Re: Add formula to multible cells !

    Yes here it comes, i think you get what i mean !

    test10.xlsm

    Petter

  6. #6
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Add formula to multible cells !

    So this should be ok
    Sub aa()
    Dim x As Long
    Dim last As Long
    last = Worksheets("Blad2").Cells(Rows.Count, 1).End(xlUp).Row
    
    For x = 1 To last
    Cells(x, 1).FormulaLocal = "=(Blad2!A" & x & ")"
    Next
    End Sub

  7. #7
    Banned User!
    Join Date
    06-13-2009
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Add formula to multible cells !

    In Tom's 4th line
    even these will work

    Range("a" & x).Formula = "=summa(sheet1!a" & x & ")"
    or
    Evaluate("a" & x) = "=summa(sheet1!a" & x & ")"
    Last edited by royUK; 04-08-2012 at 03:47 AM.

  8. #8
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Kiruna
    Posts
    163

    Re: Add formula to multible cells !

    Thanks Tom and actuary.jk everyone works fine

    Petter

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Add formula to multible cells !

    I'd prefer:
    Sub snb()
      [Blad1!A1:A1000] = [index("=Blad2!A" & row(1:1000),)]
    End Sub



+ 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