Assign Value to Variable (Excel VBA)

Closed
tor - 18 Jun 2010 à 23:06
 Kranthi - 22 Jun 2010 à 01:24
Hi
I have a variable name CountNumber.
I want it to have a value from the formula "count from A2:A500 range.

How can I write the code in VBA without putting a real formula in excel worksheet.?

2.) Suppose CountNumber already has value.
How can I put the number to a cell, say B5?
Related:

2 responses

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
19 Jun 2010 à 06:31
for number 1

You can have
CountNumber = WorksheetFunction.Sum(Range("A2:A500"))

for 2

Cells(5, "B") = CountNumber
for number 1

You can have
CountNumber = Range("A2:A500").Rows.Count