VBA Formula Errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For Each Iter In Range("Opportunities")
Debug.Print Iter.Value
If Iter.Value > 0 Then
Iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print Iter.Offset(0, 3).Value, Iter.Value

'Error at following statement
Iter.Offset(0, 5).Value = _
([ Iter.Offset(0,3).value * (1 - Iter.Offset(0,3).value)] /
Iter.Value) ^ (0.5) 'Sigma calculation
Iter.Offset(0, 2).Value = Iter.Offset(0, 3).Value - 3 *
Iter.Offset(0, 5).Value 'LCL
Iter.Offset(0, 4).Value = Iter.Offset(0, 3).Value + 3 *
Iter.Offset(0, 5).Value 'UCL
Iter.Offset(0, 6).Value = _
(Iter.Offset(0, 1).Value - Range("P_Bar").Value) /
Iter.Offset(0, 5) 'Zi calculation
Else
Iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
Iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
Iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
Iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
Iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation

End If
Next

Can someone assist?

Thanks,
Barb
 
Change following code
'Error at following statement
Iter.Offset(0, 5).Value = ([ Iter.Offset(0,3).value * (1 - _
Iter.Offset(0,3).value)] / Iter.Value) ^ (0.5) 'Sigma
calculation

with

Iter.Offset(0, 5).Value = ((Iter.Offset(0, 3).Value * (1 - _
Iter.Offset(0, 3).Value)) / Iter.Value) ^ (0.5) 'Sigma
calculation
 
I figured out the first part

Iter.Offset(0, 3).Value = "=P_Bar"

was replaced with

Iter.Offset(0, 3).Value = Evaluate("'" & ActiveSheet.Name & "'!P_Bar")

Still haven't got the second part.
 
Try this:

Dim iter As Object
For Each iter In Range("Opportunities")
Debug.Print iter.Value
If iter.Value > 0 Then
iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print iter.Offset(0, 3).Value, iter.Value

'Error at following statement
iter.Offset(0, 5).Value = _
((iter.Offset(0, 3).Value) * (1 - iter.Offset(0,
3).Value)) / _
(iter.Value ^ 0.5) 'Sigma calculation

iter.Offset(0, 2).Value = (iter.Offset(0, 3).Value - 3) * _
(iter.Offset(0, 5).Value) 'LCL

iter.Offset(0, 4).Value = (iter.Offset(0, 3).Value + 3) * _
(iter.Offset(0, 5).Value) 'UCL

' iter.Offset(0, 6).Value = _
' (iter.Offset(0, 1).Value - Range("P_Bar").Value) / _
' (iter.Offset(0, 5)) 'Zi calculation
Else
iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation
End If
Next

Sandy
 
Make sure you get rid of the underscore in the code
Sandy said:
Try this:

Dim iter As Object
For Each iter In Range("Opportunities")
Debug.Print iter.Value
If iter.Value > 0 Then
iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print iter.Offset(0, 3).Value, iter.Value

'Error at following statement
iter.Offset(0, 5).Value = _
((iter.Offset(0, 3).Value) * (1 - iter.Offset(0,
3).Value)) / _
(iter.Value ^ 0.5) 'Sigma calculation

iter.Offset(0, 2).Value = (iter.Offset(0, 3).Value - 3) * _
(iter.Offset(0, 5).Value) 'LCL

iter.Offset(0, 4).Value = (iter.Offset(0, 3).Value + 3) * _
(iter.Offset(0, 5).Value) 'UCL

' iter.Offset(0, 6).Value = _
' (iter.Offset(0, 1).Value - Range("P_Bar").Value) / _
' (iter.Offset(0, 5)) 'Zi calculation
Else
iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation
End If
Next

Sandy


Barb said:
For Each Iter In Range("Opportunities")
Debug.Print Iter.Value
If Iter.Value > 0 Then
Iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print Iter.Offset(0, 3).Value, Iter.Value

'Error at following statement
Iter.Offset(0, 5).Value = _
([ Iter.Offset(0,3).value * (1 - Iter.Offset(0,3).value)] /
Iter.Value) ^ (0.5) 'Sigma calculation
Iter.Offset(0, 2).Value = Iter.Offset(0, 3).Value - 3 *
Iter.Offset(0, 5).Value 'LCL
Iter.Offset(0, 4).Value = Iter.Offset(0, 3).Value + 3 *
Iter.Offset(0, 5).Value 'UCL
Iter.Offset(0, 6).Value = _
(Iter.Offset(0, 1).Value - Range("P_Bar").Value) /
Iter.Offset(0, 5) 'Zi calculation
Else
Iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
Iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
Iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
Iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
Iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation

End If
Next

Can someone assist?

Thanks,
Barb
 
Make sure you get rid of the underscore in the code
Sandy said:
Try this:

Dim iter As Object
For Each iter In Range("Opportunities")
Debug.Print iter.Value
If iter.Value > 0 Then
iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print iter.Offset(0, 3).Value, iter.Value

'Error at following statement
iter.Offset(0, 5).Value = _
((iter.Offset(0, 3).Value) * (1 - iter.Offset(0,
3).Value)) / _
(iter.Value ^ 0.5) 'Sigma calculation

iter.Offset(0, 2).Value = (iter.Offset(0, 3).Value - 3) * _
(iter.Offset(0, 5).Value) 'LCL

iter.Offset(0, 4).Value = (iter.Offset(0, 3).Value + 3) * _
(iter.Offset(0, 5).Value) 'UCL

' iter.Offset(0, 6).Value = _
' (iter.Offset(0, 1).Value - Range("P_Bar").Value) / _
' (iter.Offset(0, 5)) 'Zi calculation
Else
iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation
End If
Next

Sandy


Barb said:
For Each Iter In Range("Opportunities")
Debug.Print Iter.Value
If Iter.Value > 0 Then
Iter.Offset(0, 3).Value = "=P_Bar"
'This works, but I really want the VALUE, not the formula
Debug.Print Iter.Offset(0, 3).Value, Iter.Value

'Error at following statement
Iter.Offset(0, 5).Value = _
([ Iter.Offset(0,3).value * (1 - Iter.Offset(0,3).value)] /
Iter.Value) ^ (0.5) 'Sigma calculation
Iter.Offset(0, 2).Value = Iter.Offset(0, 3).Value - 3 *
Iter.Offset(0, 5).Value 'LCL
Iter.Offset(0, 4).Value = Iter.Offset(0, 3).Value + 3 *
Iter.Offset(0, 5).Value 'UCL
Iter.Offset(0, 6).Value = _
(Iter.Offset(0, 1).Value - Range("P_Bar").Value) /
Iter.Offset(0, 5) 'Zi calculation
Else
Iter.Offset(0, 5).FormulaR1C1 = "=NA()" 'Sigma calculation
Iter.Offset(0, 2).FormulaR1C1 = "=NA()" 'LCL Calculation
Iter.Offset(0, 3).FormulaR1C1 = "=NA()" 'CL Calculation
Iter.Offset(0, 4).FormulaR1C1 = "=NA()" 'UCL Calculation
Iter.Offset(0, 6).FormulaR1C1 = "=NA()" 'Zi Calculation

End If
Next

Can someone assist?

Thanks,
Barb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top