Excel addin for a series of rates!?

theta

Well-known Member
Joined
Jun 9, 2009
Messages
960
Hi All...if I could get this to work (not even sure on the approach) the entire office would have a much easier day at work :)

There is a database of rates, stored in an excel table. There are dates (in the format MMYY) and corresponding currencies (100 in total)

I would like to have a custom function where I could type

=RATELOOKUP("EUR","0911")

And the corresponding rate will appear

The excel file with the rates is stored read only in a locked folder on the network so the format and layout will not be affected

How could I macro this? - then turn the result into an addin so that everybody can take advantage of this as it is causing HUGE headache :)
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Fantastic, that helps me with the logic for retrieiving (although I will have to use a match for the ROW and COLUMN to get the correct item)

How do I turn this into a function though?

And then subsequently an addin?

:eeek:
 
Upvote 0
Upvote 0
But in that example - do you not have to run the Sub that then calls the private function?

I just want to be able to type into a cell =RATE("EUR","0911") and that is all the user interaction required

The user personal workbook looks like it may be the easier option for a small office?
 
Upvote 0
Sorry to not have pointed out that you do not need to take all of the code there. Only the function without the loop around will suffice. It's just an example in the end.
 
Upvote 0
Hmm ok...so let's saY my document is C:\PROTECTED.xlsx

How would I adjust this VB code? I am not looking up a single cell, but performing an lookup. The long formula for the lookup would be

=INDEX(PROTECTED.xlsx!LookupTable[#All],MATCH("1210",PROTECTED.xlsx!LookupTable[[#All],[ANCHOR]],0),MATCH("EUR",PROTECTED.xlsx!LookupTable[#Headers],0))

But know you can create a lookup in VB. OR add to collection and find the correct item. Or ADO and SQL

What is the best way?

Rich (BB code):
Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
    wbName As String, wsName As String, cellRef As String) As Variant
Dim arg As String
    GetInfoFromClosedFile = ""
    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    If Dir(wbPath & "\" & wbName) = "" Then Exit Function
    arg = "'" & wbPath & "[" & wbName & "]" & _
        wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
    On Error Resume Next
    GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function
 
Upvote 0
Hello

I'm trying to make it work myself... without the lookup (that could be done later on)

I have in a regular module:

Code:
Function GetInfoFromClosedFile(ByVal wbPath As String, wbName As String, wsName As String, cellRef As String) As Variant
    Dim arg As String
    GetInfoFromClosedFile = ""
    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    If Dir(wbPath & "\" & wbName) = "" Then Exit Function
    arg = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
    On Error Resume Next
    GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function

This test below works fine:

Code:
Sub test()

    MsgBox GetInfoFromClosedFile("C:", "PROTECTED.xlsx", "Sheet1", "B3")

End Sub

However, in cell A1 in the same file as the code:

=GetInfoFromClosedFile("C:","PROTECTED.xlsx","Sheet1","B3")

gives a #VALUE! error ...

Does anyone know why?

Excel 2007.
 
Upvote 0
Thanks for confirming Andrew.

I read on several sites that this is a User Defined Function. From that, I (mistakenly) assumed that it could be used in a worksheet cell. But it appears that not all UDF's can be used in worksheets. I was wrong on the terminology.
 
Upvote 0

Forum statistics

Threads
1,222,312
Messages
6,165,275
Members
451,949
Latest member
bovacik

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