Results 1 to 5 of 5

Thread: VBA instead of array formulae
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Apr 2013
    Posts
    1,055
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Default VBA instead of array formulae

    Is it possible to replace array formulae with just VBA?

    If I have the data as follows:

    Code:
    1    10
    2    25
    3    30
    and I want to sum column A and put the result in cell D1, I can record a macro to generate this code:

    Code:
    Range("D1").Select
        ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:R[2]C[-3])"
    
    


    Alternatively I can wite:

    Code:
    Range("D1").Value = Range("A1").Value+Range("A2").Value+Range("A3").Value
    


    If on the other hand I want to use the LINEST function, the recorded macro shows:

    Code:
    Range("F1:G1").Select
        Selection.FormulaArray = "=LINEST(RC[-4]:R[2]C[-4],RC[-5]:R[2]C[-5])"
    
    


    How can I rewrite this so the formula is NOT shown in Excel?

    Thanks



    Last edited by tiredofit; Aug 15th, 2019 at 09:23 AM.

  2. #2
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    22,605
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    15 Thread(s)

    Default Re: VBA instead of array formulae

    Try
    Code:
    Range("F1:G1").Select
    With Selection
        .FormulaArray = "=LINEST(RC[-4]:R[2]C[-4],RC[-5]:R[2]C[-5])"
        .Value = .Value
    End With

  3. #3
    MrExcel MVP FormR's Avatar
    Join Date
    Aug 2011
    Location
    UK
    Posts
    6,092
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA instead of array formulae

    Hi, maybe:

    Code:
    Range("F1:G1").Value = Evaluate("LINEST(B1:B3,A1:A3)")
    [code]your code[/code]

  4. #4
    Board Regular jmacleary's Avatar
    Join Date
    Oct 2015
    Location
    at a desk in the UK
    Posts
    637
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA instead of array formulae

    Hi there. You could add this code straight after:
    Code:
    Selection.Value = Selection.Value
    Just make sure automatic calculation is on.
    If my answer has helped, please vote using the Thanks or Like buttons on the left.
    John

  5. #5
    Board Regular
    Join Date
    Apr 2013
    Posts
    1,055
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA instead of array formulae

    Thanks for the suggestions.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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