hi guys need your help.
I have a problem in using the 'find-copy and loop' method,
here's my data:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name 1[/TD]
[TD]A1[/TD]
[TD]OK[/TD]
[TD]A2[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name 2[/TD]
[TD]B1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Name 3[/TD]
[TD]C1[/TD]
[TD]OK[/TD]
[TD]C2[/TD]
[TD]OK[/TD]
[TD]C3[/TD]
[TD]OK[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Name 4[/TD]
[TD]D1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]D3[/TD]
[TD]OK[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Name 5[/TD]
[TD]E1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
and this is the code I used:
what happens is:
The code does not copy all the results that I found. whereas, based on the above data should be there around 9 results but that appears there's only 8 results. what is lacking or wrong of my code.?
thanks before.
I have a problem in using the 'find-copy and loop' method,
here's my data:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name 1[/TD]
[TD]A1[/TD]
[TD]OK[/TD]
[TD]A2[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name 2[/TD]
[TD]B1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Name 3[/TD]
[TD]C1[/TD]
[TD]OK[/TD]
[TD]C2[/TD]
[TD]OK[/TD]
[TD]C3[/TD]
[TD]OK[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Name 4[/TD]
[TD]D1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]D3[/TD]
[TD]OK[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Name 5[/TD]
[TD]E1[/TD]
[TD]OK[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]....[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
and this is the code I used:
Code:
Sub Copas()
Dim DestSheet As Worksheet
Set DestSheet = Worksheets("Sheet2")
Dim sRow As Long
Dim dRow As Long
Dim sCount As Long
Dim X As Long
sCount = 0
dRow = 1
X = 1
Do Until Cells(X, 1) = ""
For sRow = Cells(X, 1) To Cells(X, 1000).End(xlToRight).Column
If Cells(X, sRow) Like "*OK*" Then
sCount = sCount + 1
dRow = dRow + 1
Cells(X, 1).Copy Destination:=DestSheet.Cells(dRow, "A")
Cells(X, sRow).Copy Destination:=DestSheet.Cells(dRow, "B")
Cells(X, sRow - 1).Copy Destination:=DestSheet.Cells(dRow, "C")
End If
Next sRow
X = X + 1
Loop
End Sub
what happens is:
The code does not copy all the results that I found. whereas, based on the above data should be there around 9 results but that appears there's only 8 results. what is lacking or wrong of my code.?
thanks before.