Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default do ... until loop issue


New to this world, so please feel free to patronise!

I am trying to asign a value of either 1 or 2 depending of th
condition of Yes or No, in two colums next to each other.

This is so that I can add up the values and determine whether I hav
all yes's.

This is what I have written so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
End Sub


The issue is that its fine for the first row, slow for the second, an
then locks up for the third.

There is something fundemental that I am missing, if you could point m
in the right direction, I would appreciate it.

Thanks

--
pjjclar
-----------------------------------------------------------------------
pjjclark's Profile: http://www.excelforum.com/member.php...fo&userid=2918
View this thread: http://www.excelforum.com/showthread.php?threadid=48908

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default do ... until loop issue

pjjclark wrote:
New to this world, so please feel free to patronise!

I am trying to asign a value of either 1 or 2 depending of the
condition of Yes or No, in two colums next to each other.

This is so that I can add up the values and determine whether I have
all yes's.

This is what I have written so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
End Sub


The issue is that its fine for the first row, slow for the second, and
then locks up for the third.

There is something fundemental that I am missing, if you could point me
in the right direction, I would appreciate it.

Thanks.


--------------------------------------

I don't recognize the problem that you asked about, but I know the solution to
the problem that you *didn't* ask about!

Have you considered dumping the whole VBA approach and just using something of
the sort:

[ ] = countif(A1:A999, "Yes")

Good luck...

Bill
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default do ... until loop issue

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

On Error Goto ws_exit
Application.EnableEvents = False

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
ws_exit:
Application.EnableEvents = True
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"pjjclark" wrote in
message ...

New to this world, so please feel free to patronise!

I am trying to asign a value of either 1 or 2 depending of the
condition of Yes or No, in two colums next to each other.

This is so that I can add up the values and determine whether I have
all yes's.

This is what I have written so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
End Sub


The issue is that its fine for the first row, slow for the second, and
then locks up for the third.

There is something fundemental that I am missing, if you could point me
in the right direction, I would appreciate it.

Thanks.


--
pjjclark
------------------------------------------------------------------------
pjjclark's Profile:

http://www.excelforum.com/member.php...o&userid=29180
View this thread: http://www.excelforum.com/showthread...hreadid=489087



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default do ... until loop issue

pjjclark,

No need to loop:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lYes As Long
Dim lNo As Long

If Target.Cells(1).Column < 12 Then Exit Sub
lYes = Application.CountIf(Range("L:L"), "Yes")
lNo = Application.CountIf(Range("L:L"), "No")
MsgBox "There are " & lYes & " ""Yes"" and " _
& lNo & " ""No"" values"

End Sub

Though I'm not sure that the change event is the best place for this....

HTH,
Bernie
MS Excel MVP


"pjjclark" wrote in message
...

New to this world, so please feel free to patronise!

I am trying to asign a value of either 1 or 2 depending of the
condition of Yes or No, in two colums next to each other.

This is so that I can add up the values and determine whether I have
all yes's.

This is what I have written so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
End Sub


The issue is that its fine for the first row, slow for the second, and
then locks up for the third.

There is something fundemental that I am missing, if you could point me
in the right direction, I would appreciate it.

Thanks.


--
pjjclark
------------------------------------------------------------------------
pjjclark's Profile: http://www.excelforum.com/member.php...o&userid=29180
View this thread: http://www.excelforum.com/showthread...hreadid=489087



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default do ... until loop issue

Another Option


Sub WorksheetC()
Dim r As Long
Dim cellVal As Boolean

r = 1
cellVal = True

Do Until IsEmpty(Cells(r, 1)) Or cellVal = False
Cells(r, 1).Select
cellVal = (Cells(r, 1) = "Yes")
r = r + 1
Loop
If cellVal = False Then MsgBox "Not all Yes!"
End Sub

Brian



"pjjclark" wrote in
message ...

New to this world, so please feel free to patronise!

I am trying to asign a value of either 1 or 2 depending of the
condition of Yes or No, in two colums next to each other.

This is so that I can add up the values and determine whether I have
all yes's.

This is what I have written so far:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long

r = 9

Do Until IsEmpty(Cells(r, 12))

If Cells(r, 12) = "Yes" Then
Cells(r, 13) = 1

ElseIf Cells(r, 12) = "No" Then
Cells(r, 13) = 2
End If
r = r + 1
Loop
End Sub


The issue is that its fine for the first row, slow for the second, and
then locks up for the third.

There is something fundemental that I am missing, if you could point me
in the right direction, I would appreciate it.

Thanks.


--
pjjclark
------------------------------------------------------------------------
pjjclark's Profile:

http://www.excelforum.com/member.php...o&userid=29180
View this thread: http://www.excelforum.com/showthread...hreadid=489087



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
For next do loop issue Christian Falde Excel Discussion (Misc queries) 4 November 11th 08 07:01 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Issue with Do Loop Linking to specific cells in pivot table Excel Programming 3 July 24th 05 10:38 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 10:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"