0
votes

I am getting a 424 runtime error, object required, but I copied my code directly from the homework that was given to us, where the worked. I just changed the range names, which I have triple checked for spelling mistakes and I know for a fact that they exist. Does anyone know why I keep getting an object error?

Private Sub Worksheet_Activate()

    wsSheet3.Range("hello").Value = 12
    wsSheet3.Range("world").Value = 30

End Sub

1
and does wsSheet3 exist? - emjaySX
I suppose those sheet events are to act on the sheet itself, and those ranges belong to it. so just remove all “wsSheet3.” s - DisplayName
Option Explicit ! <- a good start to identifying non-existent variables and typos. - AJD

1 Answers

0
votes

Just remove the wsSheet3 and replace :

wsSheet3.Range("LeadTime").Value = 6
wsSheet3.Range("NoStockoutProb").Value = 0.7

with :

Range("LeadTime").Value = 6
Range("NoStockoutProb").Value = 0.7

(Recommended since the code already belongs to the current sheet where the code VBA is)

Or declare your sheet as follow :

Dim ws as Worksheet
Set ws = ThisWorkbook.sheets("YourSheetName")
ws.Range("LeadTime").Value = 6