+ Reply to Thread
Results 1 to 7 of 7

VBA code leads to #value! in cell but works in immediate box

  1. #1
    Registered User
    Join Date
    12-24-2014
    Location
    Sunnyvale CA
    MS-Off Ver
    2010
    Posts
    4

    VBA code leads to #value! in cell but works in immediate box

    I have written a getprice function for retrieving stock tickers from yahoo and bitcoin prices from an online api. However the code for bitcoin results in an #value! in my excel cell. But it performs fine when I run the function from the immediate box in VB. I sense it's some sort of compatibility problem but I've exhausted my troubleshooting knowledge. Any help or pointers would be appreciated!

    here is the file
    https://drive.google.com/file/d/0B-C...ew?usp=sharing

    Book3.xlsm

    Book2forMrexcel.xlsm
    Last edited by bpage; 12-24-2014 at 06:47 PM. Reason: Book3 has the FIX

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA code leads to #value! in cell but works in immediate box


    As I was thinking when I read your post, does not work either from Immediate box on my side !

    So needs a crystal clear and complete explanation ‼

  3. #3
    Registered User
    Join Date
    12-24-2014
    Location
    Sunnyvale CA
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code leads to #value! in cell but works in immediate box

    Hi Marc. Ok that's an interesting twist.

    I want the code to allow me to type
    =GetPrice("BTCUSD",[date])
    in a cell and have it return the price on that date. It seems to work fine for stock tickers like "MSFT" but the bitcoin side is broken.

    When I have in the immediate box
    price=GetPrice("BTCUSD",DateValue("10-17-2014"))
    it works great! But the excel cell shows
    #VALUE!
    and that has stumped me

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA code leads to #value! in cell but works in immediate box


    Like this, your formula works on my side …

    In worksheet, MSFT does not work either !

    So it seems to be a bad conversion.

    Just control dbclose variable format and what you're affecting to it ‼
    Beginner level …

    Problem also in CsvToArray function that never open a workbook from Web …
    Last edited by Marc L; 12-24-2014 at 03:56 PM.

  5. #5
    Registered User
    Join Date
    12-24-2014
    Location
    Sunnyvale CA
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code leads to #value! in cell but works in immediate box

    The line that causes the error is
    array1 = wb.Sheets(1).Range("A1").CurrentRegion.Value

    This line only gets called if the input is "BTCUSD" because of the way the CSV is handled. Maybe there is a different way to handle the CSV as alternative to making it an array?

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA code leads to #value! in cell but works in immediate box


    The problem is you don't know the limits of a personal function …

    Better is to use an event like Worksheet_Change …

  7. #7
    Registered User
    Join Date
    12-24-2014
    Location
    Sunnyvale CA
    MS-Off Ver
    2010
    Posts
    4

    Re: VBA code leads to #value! in cell but works in immediate box

    Yep, I eliminated the CSVtoarray function by parsing the CSV directly. Now it is functioning fine.
    Thank you!

+ 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. Code works when cell is manually changed only the first time and not with vba
    By sdl2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-17-2014, 08:18 PM
  2. how can i make this code works for multiple links it only works for one link
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2014, 08:38 AM
  3. Embedding Files - Leads to Registering at Site - Leads to Introduction
    By Shantel in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 06-19-2014, 07:22 PM
  4. Replies: 1
    Last Post: 10-17-2012, 03:34 PM
  5. Organize spreadsheet of sales leads by zip code?
    By lilcolombo in forum Excel General
    Replies: 0
    Last Post: 11-24-2005, 02:50 PM

Tags for this Thread

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