What is largest value (number) that I can store in an Excel VBA variable?











up vote
2
down vote

favorite












I am using Microsoft Office Excel 2007.



Suppose I have the number 12500000000000.



Dim value1 as long

value1 = CLng(copyrng2.value)

'where copyrng2 is a range (cell) variable containing 12500000000000


The above code will fail because of overflow.



Can I store that number in any Excel (VBA) variable? If not, what can I do to store it, preferably in a format (Integer, Long, etc.) on which calculations can be performed?










share|improve this question




















  • 1




    Large Number Arithmetic
    – DavidPostill
    Feb 16 '16 at 13:57















up vote
2
down vote

favorite












I am using Microsoft Office Excel 2007.



Suppose I have the number 12500000000000.



Dim value1 as long

value1 = CLng(copyrng2.value)

'where copyrng2 is a range (cell) variable containing 12500000000000


The above code will fail because of overflow.



Can I store that number in any Excel (VBA) variable? If not, what can I do to store it, preferably in a format (Integer, Long, etc.) on which calculations can be performed?










share|improve this question




















  • 1




    Large Number Arithmetic
    – DavidPostill
    Feb 16 '16 at 13:57













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am using Microsoft Office Excel 2007.



Suppose I have the number 12500000000000.



Dim value1 as long

value1 = CLng(copyrng2.value)

'where copyrng2 is a range (cell) variable containing 12500000000000


The above code will fail because of overflow.



Can I store that number in any Excel (VBA) variable? If not, what can I do to store it, preferably in a format (Integer, Long, etc.) on which calculations can be performed?










share|improve this question















I am using Microsoft Office Excel 2007.



Suppose I have the number 12500000000000.



Dim value1 as long

value1 = CLng(copyrng2.value)

'where copyrng2 is a range (cell) variable containing 12500000000000


The above code will fail because of overflow.



Can I store that number in any Excel (VBA) variable? If not, what can I do to store it, preferably in a format (Integer, Long, etc.) on which calculations can be performed?







microsoft-excel microsoft-excel-2007 vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 16 '16 at 14:59









Ben N

28.8k1394139




28.8k1394139










asked Feb 16 '16 at 9:58









D.chan

42139




42139








  • 1




    Large Number Arithmetic
    – DavidPostill
    Feb 16 '16 at 13:57














  • 1




    Large Number Arithmetic
    – DavidPostill
    Feb 16 '16 at 13:57








1




1




Large Number Arithmetic
– DavidPostill
Feb 16 '16 at 13:57




Large Number Arithmetic
– DavidPostill
Feb 16 '16 at 13:57










4 Answers
4






active

oldest

votes

















up vote
1
down vote



accepted










The existing answer is correct in that you need to use the Double data type. That solves the problem, now I'll bring in some technical details.



The largest number that the Double data type can store (also the biggest number Excel can deal with) is 1.79769313486231570 • 10308. The biggest number that you can put in a cell (without a formula), however, is 9.99999999999999 • 10307. Note that you'll lose a good deal of precision when you're working with numbers that huge - adding a comparatively tiny number to things of that magnitude has a good chance of doing nothing. Floating point can get a little weird.



The maximum size of the Long data type is a drop in the ocean compared to Double's range; a signed 64-bit integer can only go up to 9,223,372,036,854,775,807. At least you're guaranteed to lose nothing to rounding there, as long as you're dealing with only whole numbers.



Sources: Excel specifications and limits, Data Type Summary






share|improve this answer





















  • just one more question, will double support decimal places?
    – D.chan
    Feb 18 '16 at 1:05










  • @D.chan Yes, Double does; Long doesn't.
    – Ben N
    Feb 18 '16 at 3:57










  • If you need numbers, we got numbers
    – Raystafarian
    Feb 19 '16 at 17:23


















up vote
0
down vote













You need to use Double rather than Long. With B2 like:



enter image description here



This code will throw an error:



Sub dural()
Dim d As Long
d = Range("B2").Value
End Sub


But this code will not:



Sub BigNumber()
Dim d As Double
d = Range("B2").Value
MsgBox d
End Sub


enter image description here






share|improve this answer




























    up vote
    0
    down vote













    Use the Decimal variable type. You can't declare a number as Decimal but you can store it in a Variant variable.



    Dim value1 as Variant
    value1 = CDec(copyrng2.value)


    NOTE: With the large numbers you are dealing with (12500000000000) if you try to store a decimal, Excel seems to round that number to 1 decimal place.






    share|improve this answer




























      up vote
      0
      down vote













      An excel can store only 15 digits. As far as the largest number be 999999999999999. If you try to type 16 digits number, it rounds the last number by 0 from 16th place.






      share|improve this answer








      New contributor




      Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.


















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        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',
        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%2fsuperuser.com%2fquestions%2f1041458%2fwhat-is-largest-value-number-that-i-can-store-in-an-excel-vba-variable%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        The existing answer is correct in that you need to use the Double data type. That solves the problem, now I'll bring in some technical details.



        The largest number that the Double data type can store (also the biggest number Excel can deal with) is 1.79769313486231570 • 10308. The biggest number that you can put in a cell (without a formula), however, is 9.99999999999999 • 10307. Note that you'll lose a good deal of precision when you're working with numbers that huge - adding a comparatively tiny number to things of that magnitude has a good chance of doing nothing. Floating point can get a little weird.



        The maximum size of the Long data type is a drop in the ocean compared to Double's range; a signed 64-bit integer can only go up to 9,223,372,036,854,775,807. At least you're guaranteed to lose nothing to rounding there, as long as you're dealing with only whole numbers.



        Sources: Excel specifications and limits, Data Type Summary






        share|improve this answer





















        • just one more question, will double support decimal places?
          – D.chan
          Feb 18 '16 at 1:05










        • @D.chan Yes, Double does; Long doesn't.
          – Ben N
          Feb 18 '16 at 3:57










        • If you need numbers, we got numbers
          – Raystafarian
          Feb 19 '16 at 17:23















        up vote
        1
        down vote



        accepted










        The existing answer is correct in that you need to use the Double data type. That solves the problem, now I'll bring in some technical details.



        The largest number that the Double data type can store (also the biggest number Excel can deal with) is 1.79769313486231570 • 10308. The biggest number that you can put in a cell (without a formula), however, is 9.99999999999999 • 10307. Note that you'll lose a good deal of precision when you're working with numbers that huge - adding a comparatively tiny number to things of that magnitude has a good chance of doing nothing. Floating point can get a little weird.



        The maximum size of the Long data type is a drop in the ocean compared to Double's range; a signed 64-bit integer can only go up to 9,223,372,036,854,775,807. At least you're guaranteed to lose nothing to rounding there, as long as you're dealing with only whole numbers.



        Sources: Excel specifications and limits, Data Type Summary






        share|improve this answer





















        • just one more question, will double support decimal places?
          – D.chan
          Feb 18 '16 at 1:05










        • @D.chan Yes, Double does; Long doesn't.
          – Ben N
          Feb 18 '16 at 3:57










        • If you need numbers, we got numbers
          – Raystafarian
          Feb 19 '16 at 17:23













        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        The existing answer is correct in that you need to use the Double data type. That solves the problem, now I'll bring in some technical details.



        The largest number that the Double data type can store (also the biggest number Excel can deal with) is 1.79769313486231570 • 10308. The biggest number that you can put in a cell (without a formula), however, is 9.99999999999999 • 10307. Note that you'll lose a good deal of precision when you're working with numbers that huge - adding a comparatively tiny number to things of that magnitude has a good chance of doing nothing. Floating point can get a little weird.



        The maximum size of the Long data type is a drop in the ocean compared to Double's range; a signed 64-bit integer can only go up to 9,223,372,036,854,775,807. At least you're guaranteed to lose nothing to rounding there, as long as you're dealing with only whole numbers.



        Sources: Excel specifications and limits, Data Type Summary






        share|improve this answer












        The existing answer is correct in that you need to use the Double data type. That solves the problem, now I'll bring in some technical details.



        The largest number that the Double data type can store (also the biggest number Excel can deal with) is 1.79769313486231570 • 10308. The biggest number that you can put in a cell (without a formula), however, is 9.99999999999999 • 10307. Note that you'll lose a good deal of precision when you're working with numbers that huge - adding a comparatively tiny number to things of that magnitude has a good chance of doing nothing. Floating point can get a little weird.



        The maximum size of the Long data type is a drop in the ocean compared to Double's range; a signed 64-bit integer can only go up to 9,223,372,036,854,775,807. At least you're guaranteed to lose nothing to rounding there, as long as you're dealing with only whole numbers.



        Sources: Excel specifications and limits, Data Type Summary







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 16 '16 at 14:56









        Ben N

        28.8k1394139




        28.8k1394139












        • just one more question, will double support decimal places?
          – D.chan
          Feb 18 '16 at 1:05










        • @D.chan Yes, Double does; Long doesn't.
          – Ben N
          Feb 18 '16 at 3:57










        • If you need numbers, we got numbers
          – Raystafarian
          Feb 19 '16 at 17:23


















        • just one more question, will double support decimal places?
          – D.chan
          Feb 18 '16 at 1:05










        • @D.chan Yes, Double does; Long doesn't.
          – Ben N
          Feb 18 '16 at 3:57










        • If you need numbers, we got numbers
          – Raystafarian
          Feb 19 '16 at 17:23
















        just one more question, will double support decimal places?
        – D.chan
        Feb 18 '16 at 1:05




        just one more question, will double support decimal places?
        – D.chan
        Feb 18 '16 at 1:05












        @D.chan Yes, Double does; Long doesn't.
        – Ben N
        Feb 18 '16 at 3:57




        @D.chan Yes, Double does; Long doesn't.
        – Ben N
        Feb 18 '16 at 3:57












        If you need numbers, we got numbers
        – Raystafarian
        Feb 19 '16 at 17:23




        If you need numbers, we got numbers
        – Raystafarian
        Feb 19 '16 at 17:23












        up vote
        0
        down vote













        You need to use Double rather than Long. With B2 like:



        enter image description here



        This code will throw an error:



        Sub dural()
        Dim d As Long
        d = Range("B2").Value
        End Sub


        But this code will not:



        Sub BigNumber()
        Dim d As Double
        d = Range("B2").Value
        MsgBox d
        End Sub


        enter image description here






        share|improve this answer

























          up vote
          0
          down vote













          You need to use Double rather than Long. With B2 like:



          enter image description here



          This code will throw an error:



          Sub dural()
          Dim d As Long
          d = Range("B2").Value
          End Sub


          But this code will not:



          Sub BigNumber()
          Dim d As Double
          d = Range("B2").Value
          MsgBox d
          End Sub


          enter image description here






          share|improve this answer























            up vote
            0
            down vote










            up vote
            0
            down vote









            You need to use Double rather than Long. With B2 like:



            enter image description here



            This code will throw an error:



            Sub dural()
            Dim d As Long
            d = Range("B2").Value
            End Sub


            But this code will not:



            Sub BigNumber()
            Dim d As Double
            d = Range("B2").Value
            MsgBox d
            End Sub


            enter image description here






            share|improve this answer












            You need to use Double rather than Long. With B2 like:



            enter image description here



            This code will throw an error:



            Sub dural()
            Dim d As Long
            d = Range("B2").Value
            End Sub


            But this code will not:



            Sub BigNumber()
            Dim d As Double
            d = Range("B2").Value
            MsgBox d
            End Sub


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 16 '16 at 14:33









            Gary's Student

            13.2k31729




            13.2k31729






















                up vote
                0
                down vote













                Use the Decimal variable type. You can't declare a number as Decimal but you can store it in a Variant variable.



                Dim value1 as Variant
                value1 = CDec(copyrng2.value)


                NOTE: With the large numbers you are dealing with (12500000000000) if you try to store a decimal, Excel seems to round that number to 1 decimal place.






                share|improve this answer

























                  up vote
                  0
                  down vote













                  Use the Decimal variable type. You can't declare a number as Decimal but you can store it in a Variant variable.



                  Dim value1 as Variant
                  value1 = CDec(copyrng2.value)


                  NOTE: With the large numbers you are dealing with (12500000000000) if you try to store a decimal, Excel seems to round that number to 1 decimal place.






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Use the Decimal variable type. You can't declare a number as Decimal but you can store it in a Variant variable.



                    Dim value1 as Variant
                    value1 = CDec(copyrng2.value)


                    NOTE: With the large numbers you are dealing with (12500000000000) if you try to store a decimal, Excel seems to round that number to 1 decimal place.






                    share|improve this answer












                    Use the Decimal variable type. You can't declare a number as Decimal but you can store it in a Variant variable.



                    Dim value1 as Variant
                    value1 = CDec(copyrng2.value)


                    NOTE: With the large numbers you are dealing with (12500000000000) if you try to store a decimal, Excel seems to round that number to 1 decimal place.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 5 at 17:50









                    ChrisB

                    1366




                    1366






















                        up vote
                        0
                        down vote













                        An excel can store only 15 digits. As far as the largest number be 999999999999999. If you try to type 16 digits number, it rounds the last number by 0 from 16th place.






                        share|improve this answer








                        New contributor




                        Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          up vote
                          0
                          down vote













                          An excel can store only 15 digits. As far as the largest number be 999999999999999. If you try to type 16 digits number, it rounds the last number by 0 from 16th place.






                          share|improve this answer








                          New contributor




                          Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            An excel can store only 15 digits. As far as the largest number be 999999999999999. If you try to type 16 digits number, it rounds the last number by 0 from 16th place.






                            share|improve this answer








                            New contributor




                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            An excel can store only 15 digits. As far as the largest number be 999999999999999. If you try to type 16 digits number, it rounds the last number by 0 from 16th place.







                            share|improve this answer








                            New contributor




                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 2 days ago









                            Raju Ghimire

                            1




                            1




                            New contributor




                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            Raju Ghimire is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1041458%2fwhat-is-largest-value-number-that-i-can-store-in-an-excel-vba-variable%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

                                Список кардиналов, возведённых папой римским Каликстом III

                                Deduzione

                                Mysql.sock missing - “Can't connect to local MySQL server through socket”