VBA count number of cells

  • Thread starter Thread starter filip
  • Start date Start date
F

filip

I am counting number of cells i have to iterate with next piece of code:
Dim rows

Do While Not (IsEmpty(ActiveCell))
rows = ActiveCell.Row
ActiveCell.Offset(1, 0).Select
Loop

is it possible to do the same without selecting?
 
Hi,

It's always a good idea to post code/formula you have tried but the snippet
of code you supplied will go into a very long and probably endless loop if
run so avoid doing that.

Perhaps you could explain more clearly what you are trying to do.

Mike
 
Hi
Do not use Rows as a variable, it's already used in VBA.
Is ActiveCell always in row 1, otherwise you may wish to subtract
ActiveCell.Row from the result below.
Look at this:

Dim Target as Range
Dim RowCount as Integer

Set Target = ActiveCell
Do While Not (IsEmpty(Target))
RowCount = Target.Row
Set Target = Target.Offset(1, 0)
Loop
'or
RowCount = ActiveCell.End(xlDown).Row

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top