Assign Value to Variable (Excel VBA)

Closed
tor - Jun 18, 2010 at 11:06 PM
 Kranthi - Jun 22, 2010 at 01:24 AM
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?

2 responses

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

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

for 2

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

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