VBA code with macros

L

Lacy

I'm using the visual basic editor with a macro. Using
several loops I am counting data based on several criteria
that is listed in columns. I want to look at each cell in
the column, but I don't know how many rows of data there
will be. This is the loop I'm trying to use:
For i = Worksheets("Sheet1").Range("J3") To
ActiveCell.Value <> ""

The data is being imported into excel and I don't want the
user to have to click on the last cell of the column since
I'm doing this in several columns. So activecell won't
work.

Thanks,
Lacy
 
K

Kevin

Use a nested routine to walk across the columns,
incrementing ColNum to the width of your sheet. The
following code will give you the number of "filled" rows
in the column. For each value of ColNum, RowCount will be
equal to the number of rows you need to check in that
column.

RowCount = Sheets("AE Data").Cells(Rows.Count, ColNum).End
(xlUp).Row

You could also use this to locate focus on the cell you
want, and then use activecell, if there is reason to do it
that way.

Good luck,

Kevin
 
K

Kevin

Lacy, I realized after I sent this, that I copied this
from a workbook I use it in (to be sure the syntax is
correct) and it works fine. However, I forgot to
substitute the sheet name ("AE Data") with something
generic. If you cut and paste this, be sure to put the
correct sheet name in place.

Kevin
 

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

Top