Vba loop jumping ower values

Closed
Da helpzor - Jul 21, 2009 at 07:41 AM
 Da helpzor - Jul 21, 2009 at 08:51 AM
Hello,

i have created a loop witch is a part of a bigger macro i am creating the loop is runnig fine exept one thing, the loops pupuse is to compare data and if value ""X"" > ""Y"" then replase Y with X the issue is this if a collum look like this

3
4
5
6
7


the loop ends up wit 5 as end value and if i run it one more time it will end up with 7 witch is waht i want but wy dosent it do that the first time ? here is the code

i get the impression that the loop copis the first then jump ower the last numbers

Range("B10").Select
Dim k As Integer
Dim i As Integer
Application.ScreenUpdating = False

For y = 1 To 100000
If ActiveCell = Range("J9").Offset(0, i) And ActiveCell.Offset(0, 2) = Range("I10").Offset(k, 0) And ActiveCell.Offset(0, 3).Value > Range("j10").Offset(k, i).Value Then
ActiveCell.Offset(0, 3).Copy
Range("J10").Offset(k, i).PasteSpecial
ActiveCell.Offset(1, 0).Select

Else
ActiveCell.Offset(1, 0).Select
End If

If IsEmpty(ActiveCell) Then
Range("B10").Select
k = k + 1
End If

If k > 70 Then
k = 0
i = i + 1
End If
If i > 20 Then
i = 0
k = 0
End If

Next y

Application.ScreenUpdating = True

i am grateful for any help
Related:

1 response

o.o

i fixd it just cahnged

ActiveCell.Offset(0, 3).Copy
Range("J10").Offset(k, i).PasteSpecial


to

ActiveCell.Offset(0, 3).Copy Destination:=Range("J10").Offset(k, i)


:)
2