How can I calculate a formula in Excel VBA and put its value in a variable? For example I want to set x equal to COUNTA(Sheet1!A:A)Excel VBA variable value equal to formulahow to write an excel formula in vba?Excel 2003 formula not calculating after changing it in VBACalculating formulas in excel cells with VBA?MS Excel 2007 VBA function error (Object variable or with block variable not set)VBA Evaluate function and array formula returning range of valuesHow can I put 2 variables in countA in VBA?Excel VBA - Select a range using variables & COUNTACalculate Excel formulas in VBA but display only the value in Excelexcel formula to counta based on header value

Why doesn't Adrian Toomes give up Spider-Man's identity?

Does the Long March-11 increase its thrust after clearing the launch tower?

How can I end combat quickly when the outcome is inevitable?

Is an entry level DSLR going to shoot nice portrait pictures?

Russian word for a male zebra

What is the maximum number of net attacks that one can make in a round?

Colloquialism for “see you later”

Should I give professor gift at the beginning of my PhD?

Winning Strategy for the Magician and his Apprentice

Why didn't Voldemort recognize that Dumbledore was affected by his curse?

Longest bridge/tunnel that can be cycled over/through?

SQL counting distinct over partition

How to handle self harm scars on the arm in work environment?

When would it be advantageous not apply Training Ground's cost reduction?

Using "subway" as name for London Underground?

Geopandas and QGIS Calulating Different Polygon Area Values?

What ways have you found to get edits from non-LaTeX users?

Tabular make widths equal

What setting controls moving the cursor on the command line?

How did old MS-DOS games utilize various graphic cards?

How to tell your grandparent to not come to fetch you with their car?

Is it possible to have a wealthy country without a middle class?

Overlapping String-Blocks

Is a lack of character descriptions a problem?



How can I calculate a formula in Excel VBA and put its value in a variable? For example I want to set x equal to COUNTA(Sheet1!A:A)


Excel VBA variable value equal to formulahow to write an excel formula in vba?Excel 2003 formula not calculating after changing it in VBACalculating formulas in excel cells with VBA?MS Excel 2007 VBA function error (Object variable or with block variable not set)VBA Evaluate function and array formula returning range of valuesHow can I put 2 variables in countA in VBA?Excel VBA - Select a range using variables & COUNTACalculate Excel formulas in VBA but display only the value in Excelexcel formula to counta based on header value






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















How can I calculate a formula in Excel VBA and put its value in a variable?

For example I want to set x equal to COUNTA(Sheet1!A:A)



When I write x=WorksheetFunction.COUNTA(Sheet1!A:A) I get the error




"Expected: list separator or )"











share|improve this question






























    0















    How can I calculate a formula in Excel VBA and put its value in a variable?

    For example I want to set x equal to COUNTA(Sheet1!A:A)



    When I write x=WorksheetFunction.COUNTA(Sheet1!A:A) I get the error




    "Expected: list separator or )"











    share|improve this question


























      0












      0








      0








      How can I calculate a formula in Excel VBA and put its value in a variable?

      For example I want to set x equal to COUNTA(Sheet1!A:A)



      When I write x=WorksheetFunction.COUNTA(Sheet1!A:A) I get the error




      "Expected: list separator or )"











      share|improve this question
















      How can I calculate a formula in Excel VBA and put its value in a variable?

      For example I want to set x equal to COUNTA(Sheet1!A:A)



      When I write x=WorksheetFunction.COUNTA(Sheet1!A:A) I get the error




      "Expected: list separator or )"








      excel vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 18:38









      Asger

      2,7362525




      2,7362525










      asked Mar 24 at 17:49









      user223276user223276

      83




      83






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You aren't passing the range reference to the worksheet function properly. You need to use a VBA style reference not a worksheet style reference.



          'VBA style using worksheet codename
          x = WorksheetFunction.COUNTA(Sheet1.Range("A:A"))

          'VBA style using worksheet name
          x = WorksheetFunction.COUNTA(Worksheets("Sheet1").Range("A:A"))





          share|improve this answer






























            0














            The function needs a Range, so:



            Sub kount()
            Dim r As Range, x As Long

            Set r = Sheets("Sheet1").Range("A:A")

            With Application.WorksheetFunction
            x = .CountA(r)
            End With
            End Sub





            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%2f55326728%2fhow-can-i-calculate-a-formula-in-excel-vba-and-put-its-value-in-a-variable-for%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














              You aren't passing the range reference to the worksheet function properly. You need to use a VBA style reference not a worksheet style reference.



              'VBA style using worksheet codename
              x = WorksheetFunction.COUNTA(Sheet1.Range("A:A"))

              'VBA style using worksheet name
              x = WorksheetFunction.COUNTA(Worksheets("Sheet1").Range("A:A"))





              share|improve this answer



























                1














                You aren't passing the range reference to the worksheet function properly. You need to use a VBA style reference not a worksheet style reference.



                'VBA style using worksheet codename
                x = WorksheetFunction.COUNTA(Sheet1.Range("A:A"))

                'VBA style using worksheet name
                x = WorksheetFunction.COUNTA(Worksheets("Sheet1").Range("A:A"))





                share|improve this answer

























                  1












                  1








                  1







                  You aren't passing the range reference to the worksheet function properly. You need to use a VBA style reference not a worksheet style reference.



                  'VBA style using worksheet codename
                  x = WorksheetFunction.COUNTA(Sheet1.Range("A:A"))

                  'VBA style using worksheet name
                  x = WorksheetFunction.COUNTA(Worksheets("Sheet1").Range("A:A"))





                  share|improve this answer













                  You aren't passing the range reference to the worksheet function properly. You need to use a VBA style reference not a worksheet style reference.



                  'VBA style using worksheet codename
                  x = WorksheetFunction.COUNTA(Sheet1.Range("A:A"))

                  'VBA style using worksheet name
                  x = WorksheetFunction.COUNTA(Worksheets("Sheet1").Range("A:A"))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 20:56







                  user11246173






























                      0














                      The function needs a Range, so:



                      Sub kount()
                      Dim r As Range, x As Long

                      Set r = Sheets("Sheet1").Range("A:A")

                      With Application.WorksheetFunction
                      x = .CountA(r)
                      End With
                      End Sub





                      share|improve this answer



























                        0














                        The function needs a Range, so:



                        Sub kount()
                        Dim r As Range, x As Long

                        Set r = Sheets("Sheet1").Range("A:A")

                        With Application.WorksheetFunction
                        x = .CountA(r)
                        End With
                        End Sub





                        share|improve this answer

























                          0












                          0








                          0







                          The function needs a Range, so:



                          Sub kount()
                          Dim r As Range, x As Long

                          Set r = Sheets("Sheet1").Range("A:A")

                          With Application.WorksheetFunction
                          x = .CountA(r)
                          End With
                          End Sub





                          share|improve this answer













                          The function needs a Range, so:



                          Sub kount()
                          Dim r As Range, x As Long

                          Set r = Sheets("Sheet1").Range("A:A")

                          With Application.WorksheetFunction
                          x = .CountA(r)
                          End With
                          End Sub






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 24 at 19:27









                          Gary's StudentGary's Student

                          76.8k94164




                          76.8k94164



























                              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%2f55326728%2fhow-can-i-calculate-a-formula-in-excel-vba-and-put-its-value-in-a-variable-for%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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript