Are calculations involving a large matrix using arrays in VBA faster than doing the same calculation manually...












1















I am trying to do calculations as part of regression model in Excel.



I need to calculate ((X^T)WX)^(-1)(X^T)WY. Where X, W, Y are matrices and ^T and ^-1 are denoting the matrix transpose and inverting operation.



Now when X, W, Y are of small dimensions I simply run my macro which calculates these values very very fast.



However sometimes I am dealing with the case when say, the dimensions of X, W, Y are 5000 X 5, 5000 X 1 and 5000 X 1 respectively, then the macro can take a lot longer to run.



I have two questions:




  1. Would, instead of using my macro which generates the matrices on Excel sheets and then uses Excel formulas like MMULT and MINVERSE etc. to calculate the output, it be faster for larger dimension matrices if I used arrays in VBA to do all the calculations? (I am not too sure how arrays work in VBA so I don't actually know if it would do anything to excel, and hence if it would be any quicker/less computationally intensive.)


  2. If the answer to the above question is no it would be no quicker. Then does anybody have an idea how to speed such calculations up? Or do I need to simply put up with it and wait.



Thanks for your time.










share|improve this question

























  • If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

    – Pᴇʜ
    Jan 26 '18 at 12:57











  • I don't know how to explain it really other than how I did. Sorry.

    – Tom
    Jan 26 '18 at 13:03











  • I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

    – Pᴇʜ
    Jan 26 '18 at 13:07











  • It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

    – Tom
    Jan 26 '18 at 13:10











  • this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

    – Pᴇʜ
    Jan 26 '18 at 13:13


















1















I am trying to do calculations as part of regression model in Excel.



I need to calculate ((X^T)WX)^(-1)(X^T)WY. Where X, W, Y are matrices and ^T and ^-1 are denoting the matrix transpose and inverting operation.



Now when X, W, Y are of small dimensions I simply run my macro which calculates these values very very fast.



However sometimes I am dealing with the case when say, the dimensions of X, W, Y are 5000 X 5, 5000 X 1 and 5000 X 1 respectively, then the macro can take a lot longer to run.



I have two questions:




  1. Would, instead of using my macro which generates the matrices on Excel sheets and then uses Excel formulas like MMULT and MINVERSE etc. to calculate the output, it be faster for larger dimension matrices if I used arrays in VBA to do all the calculations? (I am not too sure how arrays work in VBA so I don't actually know if it would do anything to excel, and hence if it would be any quicker/less computationally intensive.)


  2. If the answer to the above question is no it would be no quicker. Then does anybody have an idea how to speed such calculations up? Or do I need to simply put up with it and wait.



Thanks for your time.










share|improve this question

























  • If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

    – Pᴇʜ
    Jan 26 '18 at 12:57











  • I don't know how to explain it really other than how I did. Sorry.

    – Tom
    Jan 26 '18 at 13:03











  • I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

    – Pᴇʜ
    Jan 26 '18 at 13:07











  • It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

    – Tom
    Jan 26 '18 at 13:10











  • this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

    – Pᴇʜ
    Jan 26 '18 at 13:13
















1












1








1








I am trying to do calculations as part of regression model in Excel.



I need to calculate ((X^T)WX)^(-1)(X^T)WY. Where X, W, Y are matrices and ^T and ^-1 are denoting the matrix transpose and inverting operation.



Now when X, W, Y are of small dimensions I simply run my macro which calculates these values very very fast.



However sometimes I am dealing with the case when say, the dimensions of X, W, Y are 5000 X 5, 5000 X 1 and 5000 X 1 respectively, then the macro can take a lot longer to run.



I have two questions:




  1. Would, instead of using my macro which generates the matrices on Excel sheets and then uses Excel formulas like MMULT and MINVERSE etc. to calculate the output, it be faster for larger dimension matrices if I used arrays in VBA to do all the calculations? (I am not too sure how arrays work in VBA so I don't actually know if it would do anything to excel, and hence if it would be any quicker/less computationally intensive.)


  2. If the answer to the above question is no it would be no quicker. Then does anybody have an idea how to speed such calculations up? Or do I need to simply put up with it and wait.



Thanks for your time.










share|improve this question
















I am trying to do calculations as part of regression model in Excel.



I need to calculate ((X^T)WX)^(-1)(X^T)WY. Where X, W, Y are matrices and ^T and ^-1 are denoting the matrix transpose and inverting operation.



Now when X, W, Y are of small dimensions I simply run my macro which calculates these values very very fast.



However sometimes I am dealing with the case when say, the dimensions of X, W, Y are 5000 X 5, 5000 X 1 and 5000 X 1 respectively, then the macro can take a lot longer to run.



I have two questions:




  1. Would, instead of using my macro which generates the matrices on Excel sheets and then uses Excel formulas like MMULT and MINVERSE etc. to calculate the output, it be faster for larger dimension matrices if I used arrays in VBA to do all the calculations? (I am not too sure how arrays work in VBA so I don't actually know if it would do anything to excel, and hence if it would be any quicker/less computationally intensive.)


  2. If the answer to the above question is no it would be no quicker. Then does anybody have an idea how to speed such calculations up? Or do I need to simply put up with it and wait.



Thanks for your time.







excel vba excel-vba matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 26 '18 at 12:46









Pᴇʜ

24k63052




24k63052










asked Jan 26 '18 at 11:07









TomTom

61




61













  • If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

    – Pᴇʜ
    Jan 26 '18 at 12:57











  • I don't know how to explain it really other than how I did. Sorry.

    – Tom
    Jan 26 '18 at 13:03











  • I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

    – Pᴇʜ
    Jan 26 '18 at 13:07











  • It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

    – Tom
    Jan 26 '18 at 13:10











  • this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

    – Pᴇʜ
    Jan 26 '18 at 13:13





















  • If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

    – Pᴇʜ
    Jan 26 '18 at 12:57











  • I don't know how to explain it really other than how I did. Sorry.

    – Tom
    Jan 26 '18 at 13:03











  • I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

    – Pᴇʜ
    Jan 26 '18 at 13:07











  • It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

    – Tom
    Jan 26 '18 at 13:10











  • this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

    – Pᴇʜ
    Jan 26 '18 at 13:13



















If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

– Pᴇʜ
Jan 26 '18 at 12:57





If you have to deal a lot with huge matrices then Matlab might be worth a look. It is really strong with huge matrices. It might be a little over powered for your use case (I can't tell because I don't know your exact use case).

– Pᴇʜ
Jan 26 '18 at 12:57













I don't know how to explain it really other than how I did. Sorry.

– Tom
Jan 26 '18 at 13:03





I don't know how to explain it really other than how I did. Sorry.

– Tom
Jan 26 '18 at 13:03













I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

– Pᴇʜ
Jan 26 '18 at 13:07





I meant it is your decision which tool is suitable to your case. Matlab is a very powerful tool but not as easy to use as Excel. I would only switch if Excel takes a day or more to calculate it.

– Pᴇʜ
Jan 26 '18 at 13:07













It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

– Tom
Jan 26 '18 at 13:10





It normally takes a few minutes so not to bad and not worth matlab in my opinion. I was thinking about using VBA but I'm not sure if it is worth it. That is if it will take 5 minutes in excel and 4 in VBA then it is not worth it. However if it takes 5 minutes in excel and 30 seconds in VBA then I would try to do VBA, can you comment on the respective time frames with your best guess?

– Tom
Jan 26 '18 at 13:10













this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

– Pᴇʜ
Jan 26 '18 at 13:13







this highly depends on how your source data looks like. You cannot guess how big your gain in time would be with VBA. You can just code that solution in VBA and measure the time to get the difference. It also depends on your VBA code. If it is good it will be faster if it is bad it might be even slower than Excel. You see: Too many variables to make a good guess.

– Pᴇʜ
Jan 26 '18 at 13:13














2 Answers
2






active

oldest

votes


















1














Considering that the algorithm of the code is the same, the speed ranking is the following:




  1. Dll custom library with C#, C++, C, Java or anything similar

  2. VBA

  3. Excel


I have compared a VBA vs C++ function here, in the long term the result is really bad for VBA.



So, the following Fibonacci with recursion in C++:



int __stdcall FibWithRecursion(int & x)
{
int k = 0;
int p = 0;

if (x == 0)
return 0;

if (x == 1)
return 1;

k = x - 1;
p = x - 2;
return FibWithRecursion(k) + FibWithRecursion(p);
}


is exponentially better, when called in Excel, than the same complexity function in VBA:



Public Function FibWithRecursionVBA(ByRef x As Long) As Long

Dim k As Long: k = 0
Dim p As Long: p = 0

If (x = 0) Then FibWithRecursionVBA = 0: Exit Function
If (x = 1) Then FibWithRecursionVBA = 1: Exit Function

k = x - 1
p = x - 2

FibWithRecursionVBA = FibWithRecursionVBA(k) + FibWithRecursionVBA(p)

End Function





share|improve this answer
























  • Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

    – Tom
    Jan 26 '18 at 11:24











  • @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

    – Vityata
    Jan 26 '18 at 11:54











  • It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

    – Tom
    Jan 26 '18 at 13:02



















0














Better late than never:
I use matrices that are bigger, 3 or 4 dimensions, sized like 16k x 26 x 5.
I run through them to find data, apply one or two formulas or make combos with other matrices.



Number one, after starting the macro, open another application like notepad, you might have a nice speed increase ☺ !



Then, I guess you switched of screen updating etc, and turned of automatic calculation



As last: don't put the data in cells, not in arrays.
Just something like:




  • Dim Matrix1 as String ===>'put it in declarations if you want to use it in other macros as well. Remember you can not do "blabla=activecell.value2" etc anymore!!

  • In the "Sub()" code, use ReDim Matrix1(1 to a_value, 1 to 2nd_value, ... , 1 to last_value)

  • Matrix1(45,32,63)="what you want to put there"


After running, just drop the



Matrix1(1 to a_value, 1 to 2nd_value,1) at 1st sheet,



Matrix1(1 to a_value, 1 to 2nd_value,2) at 2nd sheet, etc



Switch on screen updating again, etc
In this way my calculation went from 45 minutes to just one, by avoiding the intermediary screen update
Success, I hope it is useful for somebody






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48460143%2fare-calculations-involving-a-large-matrix-using-arrays-in-vba-faster-than-doing%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Considering that the algorithm of the code is the same, the speed ranking is the following:




    1. Dll custom library with C#, C++, C, Java or anything similar

    2. VBA

    3. Excel


    I have compared a VBA vs C++ function here, in the long term the result is really bad for VBA.



    So, the following Fibonacci with recursion in C++:



    int __stdcall FibWithRecursion(int & x)
    {
    int k = 0;
    int p = 0;

    if (x == 0)
    return 0;

    if (x == 1)
    return 1;

    k = x - 1;
    p = x - 2;
    return FibWithRecursion(k) + FibWithRecursion(p);
    }


    is exponentially better, when called in Excel, than the same complexity function in VBA:



    Public Function FibWithRecursionVBA(ByRef x As Long) As Long

    Dim k As Long: k = 0
    Dim p As Long: p = 0

    If (x = 0) Then FibWithRecursionVBA = 0: Exit Function
    If (x = 1) Then FibWithRecursionVBA = 1: Exit Function

    k = x - 1
    p = x - 2

    FibWithRecursionVBA = FibWithRecursionVBA(k) + FibWithRecursionVBA(p)

    End Function





    share|improve this answer
























    • Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

      – Tom
      Jan 26 '18 at 11:24











    • @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

      – Vityata
      Jan 26 '18 at 11:54











    • It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

      – Tom
      Jan 26 '18 at 13:02
















    1














    Considering that the algorithm of the code is the same, the speed ranking is the following:




    1. Dll custom library with C#, C++, C, Java or anything similar

    2. VBA

    3. Excel


    I have compared a VBA vs C++ function here, in the long term the result is really bad for VBA.



    So, the following Fibonacci with recursion in C++:



    int __stdcall FibWithRecursion(int & x)
    {
    int k = 0;
    int p = 0;

    if (x == 0)
    return 0;

    if (x == 1)
    return 1;

    k = x - 1;
    p = x - 2;
    return FibWithRecursion(k) + FibWithRecursion(p);
    }


    is exponentially better, when called in Excel, than the same complexity function in VBA:



    Public Function FibWithRecursionVBA(ByRef x As Long) As Long

    Dim k As Long: k = 0
    Dim p As Long: p = 0

    If (x = 0) Then FibWithRecursionVBA = 0: Exit Function
    If (x = 1) Then FibWithRecursionVBA = 1: Exit Function

    k = x - 1
    p = x - 2

    FibWithRecursionVBA = FibWithRecursionVBA(k) + FibWithRecursionVBA(p)

    End Function





    share|improve this answer
























    • Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

      – Tom
      Jan 26 '18 at 11:24











    • @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

      – Vityata
      Jan 26 '18 at 11:54











    • It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

      – Tom
      Jan 26 '18 at 13:02














    1












    1








    1







    Considering that the algorithm of the code is the same, the speed ranking is the following:




    1. Dll custom library with C#, C++, C, Java or anything similar

    2. VBA

    3. Excel


    I have compared a VBA vs C++ function here, in the long term the result is really bad for VBA.



    So, the following Fibonacci with recursion in C++:



    int __stdcall FibWithRecursion(int & x)
    {
    int k = 0;
    int p = 0;

    if (x == 0)
    return 0;

    if (x == 1)
    return 1;

    k = x - 1;
    p = x - 2;
    return FibWithRecursion(k) + FibWithRecursion(p);
    }


    is exponentially better, when called in Excel, than the same complexity function in VBA:



    Public Function FibWithRecursionVBA(ByRef x As Long) As Long

    Dim k As Long: k = 0
    Dim p As Long: p = 0

    If (x = 0) Then FibWithRecursionVBA = 0: Exit Function
    If (x = 1) Then FibWithRecursionVBA = 1: Exit Function

    k = x - 1
    p = x - 2

    FibWithRecursionVBA = FibWithRecursionVBA(k) + FibWithRecursionVBA(p)

    End Function





    share|improve this answer













    Considering that the algorithm of the code is the same, the speed ranking is the following:




    1. Dll custom library with C#, C++, C, Java or anything similar

    2. VBA

    3. Excel


    I have compared a VBA vs C++ function here, in the long term the result is really bad for VBA.



    So, the following Fibonacci with recursion in C++:



    int __stdcall FibWithRecursion(int & x)
    {
    int k = 0;
    int p = 0;

    if (x == 0)
    return 0;

    if (x == 1)
    return 1;

    k = x - 1;
    p = x - 2;
    return FibWithRecursion(k) + FibWithRecursion(p);
    }


    is exponentially better, when called in Excel, than the same complexity function in VBA:



    Public Function FibWithRecursionVBA(ByRef x As Long) As Long

    Dim k As Long: k = 0
    Dim p As Long: p = 0

    If (x = 0) Then FibWithRecursionVBA = 0: Exit Function
    If (x = 1) Then FibWithRecursionVBA = 1: Exit Function

    k = x - 1
    p = x - 2

    FibWithRecursionVBA = FibWithRecursionVBA(k) + FibWithRecursionVBA(p)

    End Function






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 26 '18 at 11:11









    VityataVityata

    32.3k72453




    32.3k72453













    • Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

      – Tom
      Jan 26 '18 at 11:24











    • @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

      – Vityata
      Jan 26 '18 at 11:54











    • It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

      – Tom
      Jan 26 '18 at 13:02



















    • Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

      – Tom
      Jan 26 '18 at 11:24











    • @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

      – Vityata
      Jan 26 '18 at 11:54











    • It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

      – Tom
      Jan 26 '18 at 13:02

















    Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

    – Tom
    Jan 26 '18 at 11:24





    Sorry I don't understand are you saying that C++ > VBA > Excel but that VBA and Excel are not too much different? In terms of deal with matrices as specified above would it be worth working in VBA. E.g. If I did the calculations as previously mentioned in VBA vs Excel are we talking about VBA being a few seconds quicker or a few minutes quicker?

    – Tom
    Jan 26 '18 at 11:24













    @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

    – Vityata
    Jan 26 '18 at 11:54





    @Tom - VBA is faster than Excel in every scenario. Concerning minutes vs seconds - did it really took you minutes to calculate this ((X^T)WX)^(-1)(X^T)WY 5000 times in Excel?

    – Vityata
    Jan 26 '18 at 11:54













    It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

    – Tom
    Jan 26 '18 at 13:02





    It only calculates that once it is just that the matrices are very big. I am not sure if you are familiar with matrix calculations.

    – Tom
    Jan 26 '18 at 13:02













    0














    Better late than never:
    I use matrices that are bigger, 3 or 4 dimensions, sized like 16k x 26 x 5.
    I run through them to find data, apply one or two formulas or make combos with other matrices.



    Number one, after starting the macro, open another application like notepad, you might have a nice speed increase ☺ !



    Then, I guess you switched of screen updating etc, and turned of automatic calculation



    As last: don't put the data in cells, not in arrays.
    Just something like:




    • Dim Matrix1 as String ===>'put it in declarations if you want to use it in other macros as well. Remember you can not do "blabla=activecell.value2" etc anymore!!

    • In the "Sub()" code, use ReDim Matrix1(1 to a_value, 1 to 2nd_value, ... , 1 to last_value)

    • Matrix1(45,32,63)="what you want to put there"


    After running, just drop the



    Matrix1(1 to a_value, 1 to 2nd_value,1) at 1st sheet,



    Matrix1(1 to a_value, 1 to 2nd_value,2) at 2nd sheet, etc



    Switch on screen updating again, etc
    In this way my calculation went from 45 minutes to just one, by avoiding the intermediary screen update
    Success, I hope it is useful for somebody






    share|improve this answer




























      0














      Better late than never:
      I use matrices that are bigger, 3 or 4 dimensions, sized like 16k x 26 x 5.
      I run through them to find data, apply one or two formulas or make combos with other matrices.



      Number one, after starting the macro, open another application like notepad, you might have a nice speed increase ☺ !



      Then, I guess you switched of screen updating etc, and turned of automatic calculation



      As last: don't put the data in cells, not in arrays.
      Just something like:




      • Dim Matrix1 as String ===>'put it in declarations if you want to use it in other macros as well. Remember you can not do "blabla=activecell.value2" etc anymore!!

      • In the "Sub()" code, use ReDim Matrix1(1 to a_value, 1 to 2nd_value, ... , 1 to last_value)

      • Matrix1(45,32,63)="what you want to put there"


      After running, just drop the



      Matrix1(1 to a_value, 1 to 2nd_value,1) at 1st sheet,



      Matrix1(1 to a_value, 1 to 2nd_value,2) at 2nd sheet, etc



      Switch on screen updating again, etc
      In this way my calculation went from 45 minutes to just one, by avoiding the intermediary screen update
      Success, I hope it is useful for somebody






      share|improve this answer


























        0












        0








        0







        Better late than never:
        I use matrices that are bigger, 3 or 4 dimensions, sized like 16k x 26 x 5.
        I run through them to find data, apply one or two formulas or make combos with other matrices.



        Number one, after starting the macro, open another application like notepad, you might have a nice speed increase ☺ !



        Then, I guess you switched of screen updating etc, and turned of automatic calculation



        As last: don't put the data in cells, not in arrays.
        Just something like:




        • Dim Matrix1 as String ===>'put it in declarations if you want to use it in other macros as well. Remember you can not do "blabla=activecell.value2" etc anymore!!

        • In the "Sub()" code, use ReDim Matrix1(1 to a_value, 1 to 2nd_value, ... , 1 to last_value)

        • Matrix1(45,32,63)="what you want to put there"


        After running, just drop the



        Matrix1(1 to a_value, 1 to 2nd_value,1) at 1st sheet,



        Matrix1(1 to a_value, 1 to 2nd_value,2) at 2nd sheet, etc



        Switch on screen updating again, etc
        In this way my calculation went from 45 minutes to just one, by avoiding the intermediary screen update
        Success, I hope it is useful for somebody






        share|improve this answer













        Better late than never:
        I use matrices that are bigger, 3 or 4 dimensions, sized like 16k x 26 x 5.
        I run through them to find data, apply one or two formulas or make combos with other matrices.



        Number one, after starting the macro, open another application like notepad, you might have a nice speed increase ☺ !



        Then, I guess you switched of screen updating etc, and turned of automatic calculation



        As last: don't put the data in cells, not in arrays.
        Just something like:




        • Dim Matrix1 as String ===>'put it in declarations if you want to use it in other macros as well. Remember you can not do "blabla=activecell.value2" etc anymore!!

        • In the "Sub()" code, use ReDim Matrix1(1 to a_value, 1 to 2nd_value, ... , 1 to last_value)

        • Matrix1(45,32,63)="what you want to put there"


        After running, just drop the



        Matrix1(1 to a_value, 1 to 2nd_value,1) at 1st sheet,



        Matrix1(1 to a_value, 1 to 2nd_value,2) at 2nd sheet, etc



        Switch on screen updating again, etc
        In this way my calculation went from 45 minutes to just one, by avoiding the intermediary screen update
        Success, I hope it is useful for somebody







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 21:44









        robertpasrobertpas

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48460143%2fare-calculations-involving-a-large-matrix-using-arrays-in-vba-faster-than-doing%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine