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;
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
add a comment |
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
add a comment |
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
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
excel vba
edited Mar 24 at 18:38
Asger
2,7362525
2,7362525
asked Mar 24 at 17:49
user223276user223276
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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"))
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"))
add a comment |
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"))
add a comment |
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"))
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"))
answered Mar 24 at 20:56
user11246173
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 24 at 19:27
Gary's StudentGary's Student
76.8k94164
76.8k94164
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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