ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax error. (https://www.excelbanter.com/excel-programming/296458-syntax-error.html)

David McNally

Syntax error.
 
how does the for each cell in range synax work? I have the
following
For Each Cell In Range("I3:I9")
If Cell.Value = "" Then
'code
Next cell
which is saying that cell is empty? thanks so much

Tom Ogilvy

Syntax error.
 
It loops through the cells in the specified range one at a time and performs
the code contained within the loop structure against each cell.

--
Regards,
Tom Ogilvy

"David McNally" wrote in message
...
how does the for each cell in range synax work? I have the
following
For Each Cell In Range("I3:I9")
If Cell.Value = "" Then
'code
Next cell
which is saying that cell is empty? thanks so much




Bob Phillips[_6_]

Syntax error.
 
David,

It takes each cell ion the specified range one at a time and executes the
code between the For and the next upon that cell. So first time through,
cell will refer to I3, 2nd it will refer to I4, etc.

Don't forget your End If.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David McNally" wrote in message
...
how does the for each cell in range synax work? I have the
following
For Each Cell In Range("I3:I9")
If Cell.Value = "" Then
'code
Next cell
which is saying that cell is empty? thanks so much




Dave Peterson[_3_]

Syntax error.
 
And it's not really testing for emptiness.

The cell could be empty or it could even contain a giant formula that evaluates
to "".

=if(a3=7,"",sum(x9:x22))

When a3 = 7, the .value = "".

(and a single quote (') would qualify, too.)

If you really want empty:

if isempty(cell) then



David McNally wrote:

how does the for each cell in range synax work? I have the
following
For Each Cell In Range("I3:I9")
If Cell.Value = "" Then
'code
Next cell
which is saying that cell is empty? thanks so much


--

Dave Peterson



All times are GMT +1. The time now is 06:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com