VBA code with macros

  • Thread starter Thread starter Lacy
  • Start date Start date
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
 
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
 
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
 
Back
Top