ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Set a counta function result in a for loop (Macro Excel) (https://www.excelbanter.com/excel-programming/419965-set-counta-function-result-loop-macro-excel.html)

whitebalance

Set a counta function result in a for loop (Macro Excel)
 
Hi,
I'm trying to use a result from a counta() function.
Is it possible to set i.e.
test = counta(F2:F200)
and then use it as boundary for the for loop:
for x = 1 To test?

regards
Kristoffer

Mike H

Set a counta function result in a for loop (Macro Excel)
 
Hi,

You can do this
test = WorksheetFunction.CountA(Range("F2:F200"))

and then set up a loop like this

For X = 1 To test
' do things
Next

or even like this
For X = 1 To WorksheetFunction.CountA(Range("F2:F200"))
'do things
Next


Mike

"whitebalance" wrote:

Hi,
I'm trying to use a result from a counta() function.
Is it possible to set i.e.
test = counta(F2:F200)
and then use it as boundary for the for loop:
for x = 1 To test?

regards
Kristoffer



All times are GMT +1. The time now is 01:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com