I have been experimenting with loops and am currently stuck. I am hopingsomeone can help me or explain why my code is not working properly. I havetried the below code with for each, do while, do until, ect. I have triedvaries loops and I receive the same result and I am not sure why. The codebelow works as it should except for one item, it does not exit or end the loopwhen the value of the row equals “check”. Each time I have changed the code to experiment if it will work, italways exit’s two rows down from the cell that contains “check”. I am not surewhy. Please help!
Code:
Sub Pasting_Conditions()
Dim ws4 As Worksheet
Set ws4 = Worksheets("Practice")
Dim CDstatus As String
Dim xlrange As range, xlrange2 As range
Dim valuetofind As String, valuetofind2 As String
Dim followup As String, statusdate As String
Dim r As range, r2 As range
Dim q As range, q2 As range
Dim i As Variant
Application.EnableEvents = False
Application.ScreenUpdating = False
valuetofind = "Prior To Closing(PTC): "
Set xlrange = Worksheets("Practice").range("D93:D101")
For Each cell In xlrange
If cell.value = valuetofind Then
cell.Activate
End If
Next
Set r = ws4.range("O70")
Set q = activecell.Offset(2, 0)
Set r2 = ws4.range("q70")
Set q2 = activecell.Offset(2, 2)
valuetofind2 = "check"
Set xlrange2 = Worksheets("Practice").range("D93:D101")
For Each cell In xlrange2
If cell.value = valuetofind2 Then
Exit For
Else
r.value = q.value
r2.value = q2.value
Set r = r.Offset(1, 0)
Set q = q.Offset(1, 0)
Set r2 = r2.Offset(1, 0)
Set q2 = q2.Offset(1, 0)
End If
Next
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub