#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Do Loop

Could anyone please tell why the funnel is kept running without stopping even
after the expected task is completed.

Sub Macro()
Do Until blanks
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
Loop
End Sub

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Do Loop

On 3 Aug, 14:04, AlanW wrote:
Could anyone please tell why the funnel is kept running without stopping even
after the expected task is completed.

Sub Macro()
Do Until blanks
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
Loop
End Sub

Thank you


You have told it to run until an undeclared variable called Blanks is
true, which is never referred to again!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Do Loop

Alan,

You have a For Loop inside a Do Loop. Your For Loop will go through all
cells in A1:A10 and terminate when all cells have been processed. Your Do
Loop however will not terminate. It will terminate when the variable blanks
evaluates to true. You don't seem to really need the Do Loop in your code.
If your intent is to not go through the For loop if there are blanks in
A1:A10, then, you can do it with an If statement like this:

If Application.WorksheetFunction.CountA(Range("A1:A10 ")) = 10 Then
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
End If



--
Hope that helps.

Vergel Adriano


"AlanW" wrote:

Could anyone please tell why the funnel is kept running without stopping even
after the expected task is completed.

Sub Macro()
Do Until blanks
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
Loop
End Sub

Thank you

  #4   Report Post  
Posted to microsoft.public.excel.programming
Ray Ray is offline
external usenet poster
 
Posts: 267
Default Do Loop

If you only need the code to look at A1:A10, you should take out the
'Do Until blanks' and 'Loop' code ... worked just fine for me without
those lines...

ray

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Do Loop

Because you have not defined blanks
You don't even need it if you want to do it just for A1 to A10
Use this:

Sub Macro()
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
End Sub


"AlanW" wrote:

Could anyone please tell why the funnel is kept running without stopping even
after the expected task is completed.

Sub Macro()
Do Until blanks
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
Loop
End Sub

Thank you



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Do Loop

The do until "blanks" does nothing and the do/loop is doing nothing. All you
need is the for/next loop

Sub DocolorMacro()
For Each c In Range("A1:A10")
Select Case cell.Value
Case "W":x=1
Case "Q":x=7
Case Else:x=9
End Select
c.Offset(,1).Interior.ColorIndex = x
Next c
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"AlanW" wrote in message
...
Could anyone please tell why the funnel is kept running without stopping
even
after the expected task is completed.

Sub Macro()
Do Until blanks
For Each cell In Range("A1:A10")
Select Case cell.Value
Case "W"
cell.Offset(0, 1).Interior.ColorIndex = 1
Case "Q"
cell.Offset(0, 1).Interior.ColorIndex = 7
Case Else
cell.Offset(0, 1).Interior.ColorIndex = 9
End Select
Next
Loop
End Sub

Thank you


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
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 09:37 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"