View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default if statement conditions

Maybe using numbers and not text would be better:

For Each cell In Range("RawDataList")
fico = cell.Offset(0, 3)

If fico 0 And fico < 150 Then 'Bucket 1
PSICounts(0) = PSICounts(0) + 1

ElseIf fico = 150 And fico <= 199 Then 'Bucket 2
PSICounts(1) = PSICounts(1) + 1

ElseIf fico = 200 And fico <= 259 Then 'Bucket 3
PSICounts(2) = PSICounts(2) + 1

ElseIf fico = 260 Then 'Bucket 4
PSICounts(12) = PSICounts(12) + 1

Else
'Do nothing
End If

or

For Each cell In Range("RawDataList")
fico = cell.Offset(0, 3)
select case fico
case is = 260 : PSICounts(12) = PSICounts(12) + 1
case is = 200 : PSICounts(2) = PSICounts(2) + 1
case is = 150 : PSICounts(1) = PSICounts(1) + 1
case is 0 : PSICounts(0) = PSICounts(0) + 1
case else
'do nothing
end select
next cell


Cheer-Phil-ly wrote:

In a file that I inherited there is the following code....

For Each cell In Range("RawDataList")
fico = cell.Offset(0, 3)

If fico "" And fico < "150" Then 'Bucket 1
PSICounts(0) = PSICounts(0) + 1

ElseIf fico = "150" And fico <= "199" Then 'Bucket 2
PSICounts(1) = PSICounts(1) + 1

ElseIf fico = "200" And fico <= "259" Then 'Bucket 3
PSICounts(2) = PSICounts(2) + 1

ElseIf fico = "260" Then 'Bucket 4
PSICounts(12) = PSICounts(12) + 1

Else
'Do nothing
End If

Next cell

if fico is greater than 99 then it gets added to the correct bucket, but if
fico is under 100 (it should go into bucket 1), it doesn't, but rather it
goes into bucket 4.

I realize that the if statements have the values in double quotes, but why
would some fico numbers work and some don't.

If I take out the double quotes in the if statement then it seems to work
okay, which is understandable. I need to know why as soon as possilbe...
also is there something that is being done wrong in the beginning if
statement?


--

Dave Peterson