For Next - Do While Loop

dennypag02

New Member
Joined
Jul 11, 2005
Messages
2
Hi Everyone,

I'm having a hard time getting a loop to work. Basically I need to iterate over the entire population of students in column A and start a loop when a cell says "TestLoop". Within the TestLoop, I want to count the number of times "In" or "Out" occurs and exit after 3 "Outs" occurs. Any assistance would be greatly appreciated.

Column A Column B Column C Column D Column E
Matt In
Abby Out TestLoop
Lebron Out 1
Matt Out 2
Lebron In 1
Abby Out 3
Matt Out
Lebron In TestLoop
Matt Out 1
Jim Out 2
Lebron In 1
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
ok ,here I'm confused about "exit after 3 "Outs" occurs". "

you're taking about which "Outs" ????? with testloop or wihout testloop.
 
Upvote 0
I was confused ... while writing code but anyways you can change according to your need.

I assumed ---column A has NAME
Column B has Remark(in/OUt)
Column C has "Test loop"

Code:
Sub test()
Dim i As Long
Dim k As Long
Dim lstrow As Long
Dim oName As String
Dim oSign As String
Dim oRemark As String
Dim CountIn As Long
Dim CountOut As Long


Worksheets("Sheet1").Activate


lstrow = Cells(Rows.Count, "A").End(xlUp).Row




For i = 1 To lstrow


  oName = Cells(i, "A").Value
  oSign = Cells(i, "B").Value
  oRemark = Cells(i, "C").Value
  
  
  If StrComp(oRemark, "TestLoop", vbTextCompare) = 0 Then
  
        If CountOut = 3 Then   '''' 3  outs occured
                MsgBox "Target Matched "
               GoTo ExitPoint
        End If
    
            If StrComp(oSign, "In", vbTextCompare) = 0 Then
                CountIn = CountIn + 1
            End If
            
            If StrComp(oSign, "Out", vbTextCompare) = 0 Then
                CountOut = CountOut + 1
            End If
  End If


Next i


ExitPoint:
MsgBox "IN = " & CountIn & vbNewLine & "Out = " & CountOut




End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top