mercredi 3 juillet 2019

How to make an If Statement into a For Loop in VBA

I am making a project in VBA and I face a problem with the following code...

It says there is a object or an undefined function, but I don't understand why... Any Idea of what the problem is?

(All the variables are declared and i checked the name of the sheets)

Set FinalRange = ActiveWorkbook.Worksheets("Fiche Horaire").Range("A:A")
emptyroww = WorksheetFunction.CountA(FinalRange)

precautionroww = 0
If emptyroww > 50 Then precautionroww = emptyroww - 50

For a = precautionroww To emptyroww
    If ActiveWorkbook.Worksheets("Fiche Horaire").Cells(a, 1).Value = name Then ActiveWorkbook.Worksheets("Fiche Horaire").Cells(a, 4).Value = "it works"
Next

The message it gives is "Application-defined or object-defined error"

Aucun commentaire:

Enregistrer un commentaire