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

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현