Thread: loop help
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default loop help

On Monday, November 12, 2012 4:03:00 PM UTC-8, Matthew Dyer wrote:
I use the following code to build a chart that analyzes data ranges. I want to skip anything that results in a '0' value in the chart but i keep coming up with issues. the code:



For i = keystart + 1 To keyend

Range("n" & i).Value = step1 & "-" & step2

Range("o" & i).Formula = "=COUNTIF(H:H, ""<=" & step2 & " "")-COUNTIF(H:H, ""<" & step1 & """)"

With Range("q" & i)

.Formula = "=p" & i & "/p" & keyend + 1

.NumberFormat = "0.00%"

End With

With Range("p" & i)

.Formula = "=SUMIF(H:H, ""<=" & step2 & " "",I:I )-SUMIF(H:H, ""<" & step1 & """,I:I)"

.Style = "currency"

End With

If Range("p" & i).Value = 0 Then

Range("n" & i & ":q" & i).Value = "" '''' This blanks out the line, which is good

i = i - 1 '''' This makes me re-run the loop on the same row, which is good, but i will never equal keyend,

End If

step1 = step2 + 1

step2 = step2 + 5

Next i



how would i get the loop to continue thru each step without resulting in a never-ending loop?


Hi Matthew Dyer
Don't know if this will work in your case but try:

At the top of the code:
Application.EnableEvents = False

And at the bottom:
Application.EnableEvents = True

HTH
Regards