lundi 13 juillet 2020

Apply IF to range of cells in excel VBA

I'm trying to have the following code applied to cells 19:500 in Column I. If I remove the set Range line of code, I19 updates properly but Once i add the range, the following code stops working? Does anyone know where I'm going wrong? Thanks!

Sub Status_Load()
    Dim Cell As Range
    Dim Range As Range
    Dim Today As Date
    With Sheet1

        Set Range = .Range("I19:I500")

        For Each Cell In Range
            If Range("N19").Value = Empty Then Exit Sub

            If Range("O19").Value <> Month(Today) Then
                Range("I19").Value = "Carried"
            ElseIf Range("S19").Value <> "" Then
                Range("I19").Value = "Closed"
            Else: Range("I19").Value = "Open"
            End If
        Next Cell
    End With
End Sub

Aucun commentaire:

Enregistrer un commentaire