View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
WLMPilot WLMPilot is offline
external usenet poster
 
Posts: 470
Default Problem with For Each loop

Have already declared everything. Dave Peterson suggested an option that
worked great.

Thanks again,
Les

"Barb Reinhardt" wrote:

You also may want to declare some variables if you haven't already. I'd
recommend adding

Option Explicit

Before your Sub ... line. This will force you to declare all variables.
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"WLMPilot" wrote:

I have the following code:

begexprng = 0
Range("A" & begrng & ":A" & endrng).Select
For Each Cell In Selection
If Right(Cell.Value, 4) = "-Inc" Then
begexprng = begexprng + 1
Next Cell

I am trying to select a group of cells in column A and count the ones that
have
"-Inc". It should count any cell with either "1-Inc" or "2-Inc" There are
other values in column A also.

The problem is I am getting a compile error: Next without For.

Any ideas?

Thanks,
Les