vendredi 3 novembre 2017

Excel VBA: Single Loop + If-Statement; Run-time Error 1004

I want to loop through a column and compare all cells in that range with the value x of the cell "AD2". If the value of the cell i is smaller than the value x, I want cell i to be marked red. While running following code:

Sub Button10()
    Dim i As Long
    Dim x As Integer
    x = Range("AD2").Value
    If Cells(i, 26).Value < x Then
        Cells(i, 26).Font.Color = vbRed
        For i = 1 To 500
        Next i
    End If
End Sub

I get following error:

Run-time error '1004': Method '_Default' of object 'Range' failed.

Aucun commentaire:

Enregistrer un commentaire