dear friend,
kindly help me, which part of this code is wrong?
thankyou,
BigMe
Sub hitung()
If Worksheets("Quotation").Cells("C2") = "TH-K45R" And Worksheets("Quotation").Cells("C3") = "REGULER" Then
Worksheets("Quotation").Range("C12") = _
Application.WorksheetFunction.Sum(Worksheets("Breakdown TH-K45R")).Range("I2:M2").Value + Worksheets("Breakdown TH-K45R").Range("H202").Value
End If
End Sub
Hello BigMe,
Thank you for your question. You are getting the
“invalid qualifier” error because you have used the
closing parenthesis of the
Sum function after the worksheet name as a result it is taking the worksheet as the argument. But the arguments of the
Sum function can be a range of cells, not a worksheet. For this reason, you are getting this error.
You must use the closing parentheses after selecting all the arguments and use
“,” instead of
“+” between two arguments like the following image.
If you run this code at this stage you will still get an error named
“Invalid procedure call or argument”. The reason behind this error is, you have used the
Cells property here but you have selected a
range inside it.
Here, you can use the
Range object like the following image to get rid of this error.
Or, you can use the
Cells property. But in this case, you will have to select the
row index number and
column index number of the cell that you want to define. Have a look at the following image for a better understanding.
Finally, you can modify your code like the following code to get rid of the error and get your desired output.
Code:
Sub hitung()
If Worksheets("Quotation").Cells(2, 3) = "TH-K45R" And Worksheets("Quotation").Cells(3, 3) = "REGULER" Then
Worksheets("Quotation").Range("C12") = _
Application.WorksheetFunction.Sum(Worksheets("Breakdown TH-K45R").Range("I2:M2").Value, Worksheets("Breakdown TH-K45R").Range("H202").Value)
End If
End Sub
I hope this will solve your problem. Please let us know if you face any problems.
Regards
Mashhura Jahan