jeudi 26 octobre 2017

Excel VBA if statement ignoring loops

I've been trying to get this code to work for weeks. I can get it to 'print' to the first column and row in the table (D4). After that it seems as if it ignores the loop(s) to enter more data in each of the columns and rows thereafter.

I'm trying to get it to compare the number in the first column with a corisponding number in the third row and if they match paste the value of a cell (the 101s) in the same row under the column of the right number. If anyone can see where im going wrong it would be great. I've pasted my worksheet and code below.

Worksheet:

        1   2   3

1 101
2 101
3 101

VBA Code:

Sub Fill()
Dim col As Integer
Dim row As Integer
For col = 1 To 3
    For row = 1 To 3
        If Cells(3, col + 3) = Cells(row + 3, 1) Then
        Cells(row + 3, col + 3).Value = Cells(row + 3, col + 2)
        End If
    Next row
Next col
End Sub

Should result in

        1   2   3

1 101 .101
2 101.........101
3 101.................101

Aucun commentaire:

Enregistrer un commentaire