Custom Log Return Function

Scrabble2

New Member
Joined
Sep 25, 2014
Messages
4
I am trying to write a function that when I input an array of numbers(through selection) the function would take value 2 and return log(value 2/Value 1) and returns an array of numbers. I thought it would be simple to do but cannot get it. Any help is appreciated or if anyone has written a similar function where it performs calculations and returns an array would be helpful to learn. thanks a lot
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You mean to generate a result like this?

A​
B​
C​
D​
1​
value1​
value2​
2​
49​
59​
0.08066​
C2: =LOG(B2/A2)
3​
47​
22​
-0.32968​
4​
26​
39​
0.17609​
5​
46​
84​
0.26152​
 
Upvote 0
You mean to generate a result like this?

A​
B​
C​
D​
1​
value1​
value2​
2​
49​
59​
0.08066​
C2: =LOG(B2/A2)
3​
47​
22​
-0.32968​
4​
26​
39​
0.17609​
5​
46​
84​
0.26152​

<tbody>
</tbody>

Yes but as a function in VBA where you could highlight all Column A and B and row c would be returned
 
Upvote 0
If it's going to operate on the selection, it would have to be a Sub, not a Function, and you would invoke it via a shortcut or the Macros dialog (Alt+F8).

If it were a function, you would select (for the example) C2:C5, paste

=ScrabbleFunc(A2:A2, B2:B5)

... into the formula bar, and confirm it with Ctrl+Shift+Enter.

So ... which?
 
Upvote 0
If it's going to operate on the selection, it would have to be a Sub, not a Function, and you would invoke it via a shortcut or the Macros dialog (Alt+F8).

If it were a function, you would select (for the example) C2:C5, paste

=ScrabbleFunc(A2:A2, B2:B5)

... into the formula bar, and confirm it with Ctrl+Shift+Enter.

So ... which?

The second one please, where I could use =ScrabbleFunc(A2:A2, B2:B5)
 
Upvote 0
Here you go:

Code:
Function ScrabbleFunc(r1 As Range, r2 As Range) As Variant
    ' returns an array log(r2/r1)
    
    Dim i           As Long
    Dim j           As Long
    Dim adOut()     As Double

    ReDim adOut(1 To r1.Rows.Count, 1 To r1.Columns.Count)
    For i = 1 To r1.Rows.Count
        For j = 1 To r1.Columns.Count
            adOut(i, j) = Log(r2(i, j).Value2 / r1(i, j).Value2) / Log(10)
        Next j
    Next i
    ScrabbleFunc = adOut
End Function
 
Upvote 0
Here you go:

Code:
Function ScrabbleFunc(r1 As Range, r2 As Range) As Variant
    ' returns an array log(r2/r1)
    
    Dim i           As Long
    Dim j           As Long
    Dim adOut()     As Double

    ReDim adOut(1 To r1.Rows.Count, 1 To r1.Columns.Count)
    For i = 1 To r1.Rows.Count
        For j = 1 To r1.Columns.Count
            adOut(i, j) = Log(r2(i, j).Value2 / r1(i, j).Value2) / Log(10)
        Next j
    Next i
    ScrabbleFunc = adOut
End Function

Awesome! Thanks a lot for the help
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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