Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default number of non-empty rows on a worksheet

Hi all,

With a loop like this:

Do While ActiveCell < "" 'Loops until the active cell is blank.
...
ActiveCell.Offset(1, 0).Select
Loop

one can loop through a worksheet column until a cell is blank.

Is it also to possible to loop until the end (I mean, to continue even
when several cells are empty but non-emtpy cells are still present)??
(I would like to obtain the number of non-empty cells, or the index
of the last non-empty cell, but don't know whether such a function exists).

Thanks in advance,
Jonne.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default number of non-empty rows on a worksheet

You can use SpecialCells to find the last used cell in any range:

Set LastCellInC = Range("C:C").SpecialCells(xlCellTypeLastCell)
UsedRowsInC = LastCellInC.Row

"jonne" wrote:

Hi all,

With a loop like this:

Do While ActiveCell < "" 'Loops until the active cell is blank.
...
ActiveCell.Offset(1, 0).Select
Loop

one can loop through a worksheet column until a cell is blank.

Is it also to possible to loop until the end (I mean, to continue even
when several cells are empty but non-emtpy cells are still present)??
(I would like to obtain the number of non-empty cells, or the index
of the last non-empty cell, but don't know whether such a function exists).

Thanks in advance,
Jonne.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default number of non-empty rows on a worksheet

Set LastCellInC = Range("C:C").SpecialCells(xlCellTypeLastCell)

will give you the last used cell regardless of which column it is in

for a specific column

Set LastCelInC = cells(rows.count,3).End(xlup)

demo'd from the immediate window:

Range("C:C").SpecialCells(xlCellTypeLastCell).Sele ct
? selection.Address
$E$10
? cells(rows.Count,3).End(xlup).address
$C$9

if you want to count non-empty cells

cnt = Application.countA(columns(3))

--
Regards,
Tom Ogilvy



"K Dales" wrote in message
...
You can use SpecialCells to find the last used cell in any range:

Set LastCellInC = Range("C:C").SpecialCells(xlCellTypeLastCell)
UsedRowsInC = LastCellInC.Row

"jonne" wrote:

Hi all,

With a loop like this:

Do While ActiveCell < "" 'Loops until the active cell is blank.
...
ActiveCell.Offset(1, 0).Select
Loop

one can loop through a worksheet column until a cell is blank.

Is it also to possible to loop until the end (I mean, to continue even
when several cells are empty but non-emtpy cells are still present)??
(I would like to obtain the number of non-empty cells, or the index
of the last non-empty cell, but don't know whether such a function

exists).

Thanks in advance,
Jonne.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I specify an end to a worksheet to eliminate empty rows? Texasuser Excel Discussion (Misc queries) 2 January 24th 06 04:39 PM
empty rows at bottom of worksheet michael g Excel Discussion (Misc queries) 2 January 18th 05 09:17 PM
Saving a worksheet without empty rows Matt Tyler Excel Programming 3 November 29th 04 11:33 PM
Delete empty rows in a worksheet Scott Excel Programming 3 January 8th 04 10:09 PM
Number of rows not empty gps 4 pilots Excel Programming 3 December 2nd 03 10:36 PM


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"