Okay basically I’ve got a sales managing system that lists all the comics for sale, I’m trying to add a way to add another comic into it. It’s going fine but I need to update the formulaes that show the totals and such which I’ve tried with the code below but It’s throwing a object required error when I try to set my cellnum to the row number returned by my search.
Dim cellnum As Integer
Set cellnum = range("B4:B500").Find("TOTALS").Row
Dim cellnum_minus As Integer
Set cellnum_minus = cellnum - 1
Dim cellnum_plus As Integer
Set cellnum_plus = cellnum + 1
range("O" & cellnum).Value = "=SUM(O4:O" & cellnum_minus & ")"
range("Q" & cellnum).Value = "=AVERAGE(O4:O" & cellnum_minus & ")"
range("R" & cellnum).Value = "=MAX(R4:R" & cellnum_minus & ")"
range("S" & cellnum).Value = "=MIN(S4:S" & cellnum_minus & ")"
range("C" & cellnum_plus).Value = "=C" & cellnum & "/10"
range("D" & cellnum_plus).Value = "=D" & cellnum & "/10"
range("E" & cellnum_plus).Value = "=E" & cellnum & "/10"
range("F" & cellnum_plus).Value = "=F" & cellnum & "/10"
range("G" & cellnum_plus).Value = "=G" & cellnum & "/10"
range("H" & cellnum_plus).Value = "=H" & cellnum & "/10"
range("I" & cellnum_plus).Value = "=I" & cellnum & "/10"
range("J" & cellnum_plus).Value = "=J" & cellnum & "/10"
range("K" & cellnum_plus).Value = "=K" & cellnum & "/10"
range("L" & cellnum_plus).Value = "=L" & cellnum & "/10"
range("M" & cellnum_plus).Value = "=M" & cellnum & "/10"
range("N" & cellnum_plus).Value = "=N" & cellnum & "/10"
You do not use “set” when assigning a variable a value.
Setis used to assign a reference to an object, like if you wanted to take a Range object and assign it. LikeSet myRange = Range("A1:B2").Wrong
Correct
Also, use Long instead of Integer. VBA will convert Ints to Longs anyway, plus you avoid errors where you need to store a larger number.