+ Reply to Thread
Results 1 to 8 of 8

Use Cell Formula in VBA code

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Eindhoven, Netherlands
    MS-Off Ver
    2010
    Posts
    5

    Use Cell Formula in VBA code

    I have a Function that works in a cell.
    =dbFetch("SQL-string";"Database_name";OutputCell;;;)

    THis function returns: [Retrieved 1 Rows from dBase....] in the cell where it is placed
    It puts the outcome of the DBQuery in the cell defined as OutputCell

    THis works!

    But: For several reasons it's not that convenient to do all the DBQuery in a worksheet.
    It would be better if i could write some VBA code that uses the dbListFetch function
    SO: How can i use this in VBA

    I tried

    Testvar = [dbFetch("SQL-string";"Database_name";OutputCell;;;)]
    Testvar value becomes: Error 2015
    OutputCell doesn't seem to get a value


    Anyone any idea
    Last edited by JBeaucaire; 01-21-2015 at 07:09 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,324

    Re: Use Cell Formula in VBA code

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-21-2014
    Location
    Eindhoven, Netherlands
    MS-Off Ver
    2010
    Posts
    5

    Re: Use Cell Formula in VBA code

    Hi TMS

    Thanks for the quick response. I'll try that. But how to i get the OutputCell value to a variable in VBA?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,324

    Re: Use Cell Formula in VBA code

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-21-2014
    Location
    Eindhoven, Netherlands
    MS-Off Ver
    2010
    Posts
    5

    Re: Use Cell Formula in VBA code

    Hi TMS

    I'm not sure you understand my problem
    again the formula
    =dbFetch("SQL-string";"Database_name";OutputCell;;)

    So when i put this formula in Cell A1 and choose C4 as Outputcell then

    A1 will show: [Retrieved 1 Rows from dBase....
    C4 will show the outcome of the query: e.g. Manchester

    So how can i assign the resulting value in the OutputCell to a variable. Can declare a variable and put that in the formula. Something like:

    Dim OutputCell as ??
    Testvar = "[dbFetch(""SQL-string"";""Database_name"";" & OutputCell & ";;;)]"
    MsgBox OutputCell
    Last edited by JBeaucaire; 01-21-2015 at 07:09 PM.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,324

    Re: Use Cell Formula in VBA code

    I'm not sure you understand my problem
    I'm sure you're right. I've asked for others to take a look.

  7. #7
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    423

    Re: Use Cell Formula in VBA code

    Not quite sure if this is what you are asking for...
    Please Login or Register  to view this content.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,987

    Re: Use Cell Formula in VBA code

    What you're doing is essentially using Evaluate, which means Outputcell is just the address of a range and to get the value of that range, you'd have to read the cell, not the variable. So (and I can't say if this will work) it would be:

    Please Login or Register  to view this content.
    (note that Evaluate expects US style formulas, hence the commas)

    Assuming this function comes from a COM add-in, can you set a reference to that add-in? (it may not be COM exposed) If so, you could call the method directly and pass the Strings and Ranges as arguments.
    Everyone who confuses correlation and causation ends up dead.

+ 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. need a formula or vba code to change cell value form another cell
    By yusufugan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2013, 10:15 AM
  2. Replies: 3
    Last Post: 06-19-2013, 03:40 AM
  3. [SOLVED] VB Code to add Formula in Cell
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2013, 10:54 AM
  4. [SOLVED] Code to delete cell contents IF the result of a formula in the cell = 0
    By jayjaynz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-22-2013, 03:58 AM
  5. VBA Code: Help to Use a Formula which needs to be pasted in a cell
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2012, 08:05 AM

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