loop doubt

JoanaMartins

New Member
Joined
Jul 14, 2016
Messages
29
Can anyone please tell me what i am doing wrong on my loop.
it goes on and on until it crashes excel.

i tried it in so many ways.
Can you help me please.
What I need it to do is to continue to find every w that is on the list.

Thank you in advance

Code:
Sub tentativa()





Dim w As Range
Dim t As Long
Dim i As Long


Dim cs As Worksheet
Dim ps As Worksheet


Set cs = Sheets("Crono")
Set ps = Sheets("Projetos NOVO")


t = cs.Cells(cs.Rows.Count, 1).End(xlUp).Row


For i = 8 To t


    Set w = ps.Range("C:C").Find(cs.Cells(i, 1).Value)
            
    If Not (w Is Nothing) Then
    
    Do
    
       
       If InStr(1, w.Offset(0, 1).Value, cs.Cells(i, 3).Value, vbTextCompare) > 0 Then
            cs.Cells(i, 4).Value = w.Offset(0, 15).Value
            cs.Cells(i, 5).Value = w.Offset(0, 16).Value
    End If
    
    Loop While Not w Is Nothing
    
    End If
    
      
Next i




End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
As far as I can see if w is not Nothing then the Do...Loop While will be endless.

What is the code actually meant to do?
 
Last edited:
Upvote 0
if the value is found (w) it does the action i said.
but what it happens without the loop is that it finds the first one, does the action and then it goes to another cell without looking if there is another value that is equal to the first one.

That is why i need the loop. I want the loop to stop when there is no more w.

Can you help me?
 
Upvote 0
What's the purpose of the Do...Loop While loop?

All it appears to do is repeat the same code over and over.
 
Upvote 0
so:

1 - it goes to a sheet row 8
2 - takes the value that is on that cell
3 - find, on another sheet, the cell that contains that value
4 - if it finds then do some actions (that includes another if but this is constant)


what happens now (without the loop):

5 - goes to row 9
6 - takes the value that is on that cell
7 - find, on another sheet, the cell that contains that value
8 - if it finds then do some actions (that includes another if but this is constant)

and so on until t


what i need it to do (include a step after 4):

5 - go over the list again to find another value that is equal. if it finds do the actions. when there is no more values on that list then
6 - goes to row 9 and do the exact same thing until row t

am i being clear?
I am so sorry for my english!
 
Upvote 0
So you want to find every occurence of the value(s) from the sheet 'Crono' in column C on sheet 'Projetos NOVO'?
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,880
Members
449,411
Latest member
AppellatePerson

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