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AL6,
IF(AF6=140,AJ6+AK6+AL6,
IF(AF6=141,AJ6+AK6+AL6+AM6,
IF(AF6=142,AJ6+AK6+AL6+AM6,
IF(AF6=143,AJ6+AK6+AL6+AM6,
IF(AF6=144,AJ6+AK6+AL6,
IF(AF6=145,AJ6+AK6+AL6,
IF(AF6=146,2*AJ6+AK6+2*AL6,
IF(AF6=147,AJ6+AK6+AL6,
IF(AF6=148,AJ6+AK6+AL6+AM6,
IF(AF6=149,AJ6+AK6+AL6+AM6,
IF(AF6=150,AJ6+AK6+AL6+AM6,
IF(AF6=151,AJ6+AK6+AL6+AM6,
IF(AF6=152,2*AJ6+AK6+2*AL6,
IF(AF6=153,AJ6+AK6+AL6+AM6+AN6,
IF(AF6=154,AJ6+AK6+AL6+AM6+AN6,
IF(AF6=155,AJ6+AK6+AL6+AM6+AN6,
IF(AF6=156,AJ6+AK6+AL6+AM6+AN6+AO6,
IF(AF6=157,2*AJ6+2*AK6+AL6,
IF(AF6=158,2*AJ6+2*AK6+AL6,
IF(AF6=159,2*AJ6+2*AK6+AL6,
IF(AF6=160,2*AJ6+2*AK6+AL6,
IF(AF6=161,AJ6+AK6+AL6+AM6,
IF(AF6=162,AJ6+AK6+AL6,
IF(AF6=163,AJ6+AK6+AL6,0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/1000,0.005)
Errors:
i cant give more than 64 arguments
You have Entered too many arguments to this function

Can i get help with this formula or any alternative way?

Tnx for Looking my Thread
 
With UDF can I create more than 64 arguments?
You won't need to, as many can be combined!

Can I get help with UDF
Sure, once you answer the questions I asked surrounding this:
If you need more help in writing it, is this always going to be on JUST cell AF6, or multiple cells?
If multiple cells, are they always in column AF?
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Upvote 0
OK. I have started this for you. I have done for values 100-113. You can see how for values that have the same calculation (100 and 104, and then 105 - 113), I showed how you can lump them together so you do not need to repeat the calculations). You should be able to detect the pattern and do the rest (it will be a good test). Just keep adding for "Case" statement blocks before the "Case Else" (which is just a catch-all for everything else not matching one of the values being checked for).
Code:
Function MyCalc(rng As Range) As Double
'   rng = single cell in column AF

    Application.Volatile
    
    Dim r As Long

'   Make sure column is AF and only one cell being called
    If (rng.Count > 1) Or (Left(rng.Address, 4) <> "$AF$") Then
        MyCalc = 0
        Exit Function
    End If
    
'   Get row number
    r = rng.Row
    
'   Perform calculation based on value of cell
    Select Case rng.Value
        Case 100, 104
            MyCalc = 2 * Cells(r, "AJ") + 2 * Cells(r, "AK") + Cells(r, "AO")
        Case 101
            MyCalc = 2 * Cells(r, "AJ") + 2 * Cells(r, "AK") + Cells(r, "AL")
        Case 102
            MyCalc = 4 * Cells(r, "AJ") + Cells(r, "AO")
        Case 103
            MyCalc = 2 * Cells(r, "AJ") + 2 * Cells(r, "AK") + 4 * Cells(r, "AO")
        Case 105 To 113
            MyCalc = 2 * Cells(r, "AJ") + 2 * Cells(r, "AK") + 2 * Cells(r, "AL")
        Case Else
            MyCalc = 0
    End Select
                
End Function
You would then just use it like any other function in Excel, i.e.
Code:
=MyCalc(AF6)
 
Upvote 0
I am trying to do it in Excel,I am not Getting Result
I have Modified Column Reference
Can You Please cross check this
Code:
    Dim r As Long

'   Make sure column is AF and only one cell being called
    If (rng.Count > 1) Or (Left(rng.Address, 4) <> "$O$") Then
        MyCalc = 0
        Exit Function
    End If
    
'   Get row number
    r = rng.Row
    
'   Perform calculation based on value of cell
    Select Case rng.Value
        Case 100, 104
            MyCalc = 2 * Cells(r, "S") + 2 * Cells(r, "T") + Cells(r, "X")
        Case 101
            MyCalc = 2 * Cells(r, "S") + 2 * Cells(r, "T") + Cells(r, "U")
        Case 102
            MyCalc = 4 * Cells(r, "S") + Cells(r, "X")
        Case 103
            MyCalc = 2 * Cells(r, "S") + 2 * Cells(r, "T") + 4 * Cells(r, "X")
        Case 105 To 113
            MyCalc = 2 * Cells(r, "S") + 2 * Cells(r, "T") + 2 * Cells(r, "U")
        Case Else
            MyCalc = 0
            
    End Select
                
End Function
 
Upvote 0
What column are you trying to check?
If it is column O, then you want to take the left 3 characters, not 4, i.e.
Code:
(Left(rng.Address,[COLOR=#ff0000][B] 3[/B][/COLOR]) <> "$O$")
 
Upvote 0
rng.address returns the cell address, not the cell contents.

Originally, we were limiting it to cells in column AF. If you return the address of any cell in AF using rng.address, it will return something like $AF$100 (for cell AF100).
So, we were checking the first four characters of the address for "$AF$.

However, now that you are checking row O, the column reference is one character less. So we are looking for "$O$", which is only 3 characters.

Does that make sense now?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top