Loop don't work

I

If

Hello,

I have this procedure but it does not work.
This procedure does not take all the data.

What I want to do?
I want to take data from the sheet "Datas2" and insert in the sheet "Datas".
I take a column 1 in each sheet.

Must use "FOR i= / Next i" ?

Thanks in advance for your help.

--------------------------------------------------------------------------
Sub Searchdatas()
Dim NNumber As String
Dim Condition As Boolean
Dim i, j As Integer
Sheets("Datas").Select
i = 1
Do
NNumber = Cells(i, 1).Value
j = 1
Condition = False
Do
If Nom = Sheets("Datas2").Cells(j, 1).Value Then
Sheets("Datas").Cells(i, 3).Value =
Sheets("Datas2").Cells(j, 3).Value
Sheets("Datas").Cells(i, 4).Value =
Sheets("Datas2").Cells(j, 4).Value
Condition = True
End If
j = j + 1
Loop While (Cells(j - 1, 1).Value <> "" And Condition = False)
i = i + 1
Loop While Cells(i - 1, 1).Value <> ""
End Sub

--------------------------------------------------------------------------
 
J

Jim Cone

In the code line: "If Nom = Sheets("Datas2").Cells(j, 1).Value Then",
Nom has no value assigned to it so the comparison will always be False.
--
Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html

..
..
..

"If" <[email protected]>
wrote in message
Hello,

I have this procedure but it does not work.
This procedure does not take all the data.

What I want to do?
I want to take data from the sheet "Datas2" and insert in the sheet "Datas".
I take a column 1 in each sheet.

Must use "FOR i= / Next i" ?
Thanks in advance for your help.

----------------------------------------
Sub Searchdatas()
Dim NNumber As String
Dim Condition As Boolean
Dim i, j As Integer
Sheets("Datas").Select
i = 1
Do
NNumber = Cells(i, 1).Value
j = 1
Condition = False
Do
If Nom = Sheets("Datas2").Cells(j, 1).Value Then
Sheets("Datas").Cells(i, 3).Value =
Sheets("Datas2").Cells(j, 3).Value
Sheets("Datas").Cells(i, 4).Value =
Sheets("Datas2").Cells(j, 4).Value
Condition = True
End If
j = j + 1
Loop While (Cells(j - 1, 1).Value <> "" And Condition = False)
i = i + 1
Loop While Cells(i - 1, 1).Value <> ""
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top