+ Reply to Thread
Results 1 to 3 of 3

Error with using VBA array values in formula

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Error with using VBA array values in formula

    I want to create an array from a sheet called Data (with a named range "Database") every time the worksheet opens, and then all calculations can be done from the array rather than referring to the sheet all the time. To Create an array I did the following:

    IN MODULE 1:
    Public 1_comp As Variant

    Public Sub Auto_open()
    1_comp = Worksheets("Data").Range("Database").Value
    End Sub


    Then I want to create my own formulas and use array values in it, eg:
    IN MODULE 2:
    Function 2_molwt(id)

    2_molwt = 1_comp(id, 17)

    End Function


    The array works fine by itself, I can paste it to another sheet and it's perfect, but once I try to use it in the function it is as if the function does not know the array exists. How do I fix this, can anyone please help me?

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Error with using VBA array values in formula

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Registered User
    Join Date
    04-11-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Error with using VBA array values in formula

    I want to create an array from a sheet called Data (with a named range "Database") every time the worksheet opens, and then all calculations can be done from the array rather than referring to the sheet all the time. To Create an array I did the following:

    IN MODULE 1:
    Please Login or Register  to view this content.

    Then I want to create my own formulas and use array values in it, eg:
    IN MODULE 2:
    Please Login or Register  to view this content.

    The array works fine by itself, I can paste it to another sheet and it's perfect, but once I try to use it in the function it is as if the function does not know the array exists. How do I fix this, can anyone please help me?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] #VALUE! Error In With Array Formula
    By DDM64 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-29-2013, 11:17 AM
  2. Searching for user defined value in range, sending only these values to array ERROR
    By sgonzalez90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2013, 01:02 AM
  3. Error putting array values into a range on a worksheet......should work but does not
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2011, 03:29 PM
  4. Error #NUM! - Array Formula
    By Shermaine2010 in forum Excel General
    Replies: 2
    Last Post: 08-21-2011, 03:44 AM
  5. Comparing a string to values in an array resulting in a Run time Error 1004
    By sgreni in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2009, 04:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1