Consulting

Results 1 to 5 of 5

Thread: Filling cells with a formula

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Filling cells with a formula

    I have a macro written that fills in for only one cell:

    [vba]Sub spread()
    '
    ' spread Macro
    '
    Windows("Bid List.xlsx").Activate

    Range("T2").Select
    ActiveCell.FormulaR1C1 = "=RC[-10]-RC[-1]"
    Range("T2").Select
    [/vba]
    But I would like the macro to copy this formula down and fill in for every row that exists. How do I write a general macro to copy this formula down for each row that exists?
    Last edited by Aussiebear; 09-01-2011 at 04:08 PM. Reason: Added vba tags to code

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Selecting is not nessesary
    [VBA]With Workbooks("Bid List.xlsx").Sheets("Sheet1")
    With .Range("T:T")
    Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlup)).FormulaR1C1 = "=RC[-10]-RC[-1]"
    End With
    End With[/VBA]

  3. #3
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Thanks for the help! One last question..

    In my spreadsheet, i have a the following located in column E..starting at cell E2:

    A1
    cover
    A2
    cover
    A3
    cover
    etc..

    And for each row, I have EVAL values in column S and Spread values in column T. However, I only want to dispaly those values for A1, A2, A3 rows..I dont want those values displayed for the cover rows.

    How do I write a macro to have those values displayed for only A1, A2, A3, etc.. and not for the cover rows?

  4. #4
    VBAX Regular Chabu's Avatar
    Joined
    Dec 2010
    Location
    Brussels
    Posts
    85
    Location
    That's easy, just put the values of the same function into the spread of the square of the EVAL/2 but only if starting at A1,...
    Then cover with values you don't want displayed and state your question so we can understand it. :-)

    Now seriously, you will have to state your question better or at least provide a starting spreadsheet...

    Greetings

  5. #5
    Banned VBAX Regular
    Joined
    Aug 2011
    Posts
    23
    Location

    Smile

    Quote Originally Posted by mikerickson
    Selecting is not nessesary
    [vba]With Workbooks("Bid List.xlsx").Sheets("Sheet1")
    With .Range("T:T")
    Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlup)).FormulaR1C1 = "=RC[-10]-RC[-1]"
    End With
    End With[/vba]
    I admire your method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •