dimanche 26 avril 2020

If Not Statement not working Properly Within a Loop in Excel VBA

I am trying to create and IF NOT statement within a loop. I wish to make it so, that if that cell does not have the values I am looking for a formula gets inserted in another column of the same row. Right now the If not statement is being ignored and all the cells get the formula.

Sub Example()
Dim Sales As Range
Dim cell As Range

lr = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row

Set Sales= Workbooks("Sales.xlsm").Sheets("Sales").Range("B2:B" & lr)

 For Each cell In Sales



    If Not cell.Value = "Monday" Or cell.Value = "Tuesday" Then

    cell.Offset(0, 12).FormulaR1C1 = "=RC[-3]*RC[-1]"



    End If

Next

End Sub

Aucun commentaire:

Enregistrer un commentaire