Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default why can't 'Do While Each Cell in Range...'?

Thanks in advance.
I have some code that finds the first non-zero cell in a
row:
Dim cell as Range
RowNumber=1
For Each cell In Range("D1:" & ActiveSheet.Range
("D65536").End(xlUp).Address)
If cell = 0 then
RowNumber = RowNumber + 1 'increase by one row
Else
Exit For
End If
Next
But I figure I could get this down a line or two by:
Do While Each cell in Range("D1:" & ActiveSheet.Range
("D65536").End(xlUp).Address) < 0
RowNumber=RowNumber+1
Loop
But I get a syntax error (the line goes red) when I type
in the above Do While...
Is the 'each' code useable in Do Whiles?
If not, is there something else I can do?
Thanks again!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default why can't 'Do While Each Cell in Range...'?

Ian,

You can't use that structure, but you could use:

RowNumber = Application.CountIf(Range("D1",
Range("D65536").End(xlUp)), 0) +1

HTH,
Bernie
MS Excel MVP

"Ian Elliott" wrote in message
...
Thanks in advance.
I have some code that finds the first non-zero cell in a
row:
Dim cell as Range
RowNumber=1
For Each cell In Range("D1:" & ActiveSheet.Range
("D65536").End(xlUp).Address)
If cell = 0 then
RowNumber = RowNumber + 1 'increase by one row
Else
Exit For
End If
Next
But I figure I could get this down a line or two by:
Do While Each cell in Range("D1:" & ActiveSheet.Range
("D65536").End(xlUp).Address) < 0
RowNumber=RowNumber+1
Loop
But I get a syntax error (the line goes red) when I type
in the above Do While...
Is the 'each' code useable in Do Whiles?
If not, is there something else I can do?
Thanks again!



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
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
RANGE EXCEL copy cell that meets criteria in a range confused Excel Worksheet Functions 3 March 27th 08 01:41 PM
copy range and paste into every 3rd cell of new range thomsonpa New Users to Excel 4 December 3rd 07 01:47 PM
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM


All times are GMT +1. The time now is 11:34 PM.

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

About Us

"It's about Microsoft Excel"