Hi,
I tried with your suggestions, still i am getting #value error whenever a new workbook is opened. Again i need to click on the cell where formula is there to give results.
Here is the complete code. Please do the needful.
Function anchor(cellValue As String) As Double
Application.Volatile
Dim result As Double
Dim cell As Range
Set cell = Application.Caller
Dim F As Double, N As Double, K As Double, O As Double, P As Double, S As Double, T As Double, U As Double, Q As Double, R As Double
'Bolt Dia
F = cell.Offset(0, -14).Value
'H
K = cell.Offset(0, -11).Value
'LB
N = cell.Offset(0, -8).Value
'DIA
O = cell.Offset(0, -7).Value
't
P = cell.Offset(0, -6).Value
'a OR A
Q = cell.Offset(0, -5).Value
't
R = cell.Offset(0, -4).Value
'F
S = cell.Offset(0, -3).Value
'G
T = cell.Offset(0, -2).Value
'G2
U = cell.Offset(0, -1).Value
Select Case cellValue
Case 1
result = Formula1(F, N, K)
Case "1S"
result = Formula2(F, N, K)
Case 2
result = Formula3(F, N)
Case "2S"
result = Formula4(F, N)
Case 3
result = Formula5(F, N, O, P)
Case "3S"
result = Formula6(F, N, O, P)
Case 4
result = Formula7(F, N, O, P, T, S)
Case 7
result = Formula8(F, N, Q, R, T, S)
Case 5
result = Formula9(F, N, O, P, T, S, U)
Case 6
result = Formula10(F, N, Q, R, S, T)
Case Else
result = 0 ' or any other default value you want to assign
End Select
anchor = result
End Function
Function Formula1(F As Double, N As Double, K As Double) As Double
Formula1 = WorksheetFunction.Pi() * F ^ 2 / 4 * (N + K - 8 * F + 2 * WorksheetFunction.Pi() * F) / 1000000000 * 7850 + _
1 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15"))
End Function
Function Formula2(F As Double, N As Double, K As Double) As Double
Formula2 = WorksheetFunction.Pi() * F ^ 2 / 4 * (N + K - 8 * F + 2 * WorksheetFunction.Pi() * F) / 1000000000 * 7850 + _
1 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15"))
End Function
Function Formula3(F As Double, N As Double) As Double
Formula3 = WorksheetFunction.Pi() * F ^ 2 / 4 * N / 1000000000 * 7850 + _
3 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15"))
End Function
Function Formula4(F As Double, N As Double) As Double
Formula4 = WorksheetFunction.Pi() * F ^ 2 / 4 * N / 1000000000 * 7850 + _
3 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15"))
End Function
Function Formula5(F As Double, N As Double, O As Double, P As Double) As Double
Formula5 = WorksheetFunction.Pi() * F ^ 2 / 4 * N / 1000000000 * 7850 + _
4 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
WorksheetFunction.Pi() / 4 * O ^ 2 * P / 1000000000 * 7850
End Function
Function Formula6(F As Double, N As Double, O As Double, P As Double) As Double
Formula6 = WorksheetFunction.Pi() * F ^ 2 / 4 * N / 1000000000 * 7850 + _
4 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
WorksheetFunction.Pi() / 4 * O ^ 2 * P / 1000000000 * 7850
End Function
Function Formula7(F As Double, N As Double, O As Double, P As Double, T As Double, S As Double) As Double
Formula7 = WorksheetFunction.Pi() * F ^ 2 / 4 * (N) / 1000000000 * 7850 + _
3 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
WorksheetFunction.Pi() / 4 * O ^ 2 * P / 1000000000 * 7850 + _
WorksheetFunction.Pi() / 4 * ((T + 2 * IIf(F <= 36, 2, 2.6)) ^ 2 - T ^ 2) * S / 1000000000 * 7850 + _
2 * (1.5 * F) * (2 * F) * 6 / 1000000000 * 7850
End Function
Function Formula8(F As Double, N As Double, Q As Double, R As Double, T As Double, S As Double) As Double
Formula8 = WorksheetFunction.Pi() * F ^ 2 / 4 * (N - R) / 1000000000 * 7850 + _
2 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
Q ^ 2 * R / 1000000000 * 7850 + _
WorksheetFunction.Pi() / 4 * ((T + 2 * IIf(F <= 36, 2, 2.6)) ^ 2 - T ^ 2) * S / 1000000000 * 7850 + _
2 * 0.7 * Q * (Q - 20 - F) * 0.5 * R / 1000000000 * 7850 + _
WorksheetFunction.Pi() * ((T + 2 * IIf(F <= 36, 2, 2.6)) + 20) ^ 2 / 4 * 6 / 1000000000 * 7850
End Function
Function Formula9(F As Double, N As Double, O As Double, P As Double, T As Double, S As Double, U As Double) As Double
Formula9 = WorksheetFunction.Pi() * F ^ 2 / 4 * (N + N - S - P + 2 * F) / 1000000000 * 7850 + _
4 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
WorksheetFunction.Pi() / 4 * O ^ 2 * P / 1000000000 * 7850 + _
WorksheetFunction.Pi() / 4 * ((T + 2 * IIf(F <= 36, 2, 2.6)) ^ 2 - T ^ 2) * S / 1000000000 * 7850 + _
WorksheetFunction.Pi() / 4 * ((U + 2 * IIf(F <= 36, 2, 2.6)) ^ 2 - U ^ 2) * (N - S - P + 2 * F - 6) / 1000000000 * 7850 + _
2 * (1.5 * F) * (2 * F) * 6 / 1000000000 * 7850 + _
WorksheetFunction.Pi() * (U + F) ^ 2 / 4 * 6 / 1000000000 * 7850
End Function
Function Formula10(F As Double, N As Double, Q As Double, R As Double, S As Double, T As Double) As Double
Formula10 = 2 * WorksheetFunction.Pi() * F ^ 2 / 4 * N / 1000000000 * 7850 + _
2 * 3 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CW2:CW15")) + _
2 * Application.WorksheetFunction.XLookup(F, Worksheets("3.Data").Range("CY2:CY15"), Worksheets("3.Data").Range("CX2:CX15")) + _
2 * Q * (2 * Q + 150) * R / 1000000000 * 7850 + _
2 * WorksheetFunction.Pi() / 4 * ((T + 2 * IIf(F <= 36, 2, 2.6)) ^ 2 - T ^ 2) * S / 1000000000 * 7850 + _
2 * (150 + 1.5 * F) * (2 * F) * 6 / 1000000000 * 7850
End Function
Regards,
Veera