+ Reply to Thread
Results 1 to 9 of 9

Vlookup requires update links to server file everytime

  1. #1
    Registered User
    Join Date
    04-13-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Vlookup requires update links to server file everytime

    I am a newbie in Excel VBA. Please find my scenario below.
    I have a source file on server: \\server\Database\Sample.csv (Gets updated with new sample info every night. File name is the same).
    File on desktop: c:\April.xlsx (I would like to scan a barcode and vlookup info from server file), here is the macro I recorded.

    Sub InsertName ()
    Activecell.formulaR1C1 = "=vlookup(RC[-1],\\server\Database\Sample.csv\sample!$A:$C,2,false)
    End sub

    The formula works when I have the source file open. But when I close the file, it works sometimes and other times it gives an error, sometimes it asks me to update values/links to source file. I do not know why it is not reliable. Any help with this will be appreciated.

    Thanks

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Vlookup requires update links to server file everytime

    Hi Sureshks,


    Welcome to the forum.

    I would suggest you to update your code to open that server file and close that when vlookup is done....
    Also as an option, have you included the server name or the drive letter in you code when you say \\server\..?

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    04-13-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Vlookup requires update links to server file everytime

    Hi Dilipandey,
    thanks for your response. Yes, I have included the server name in the code but somehow the macro keeps asking for "Update Values". Is there a way we can to use variables or constants for the server file?
    I guess adding a code to open the source file each time should work, but since the files are huge it will slow down the macro.

  4. #4
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Vlookup requires update links to server file everytime

    Hi Sureshks,

    Since it is a formula where the server name is used, hence it will ask for updation... it is similar to a formula where we give a reference to other workbook and when calculating / opening that file again, it asks for link updation. So no issue on this front. thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  5. #5
    Registered User
    Join Date
    04-13-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Vlookup requires update links to server file everytime

    Hi Dilipandey,
    Thanks for your response.
    The issue here is that I have a file on the server, (path and name are fixed). If I need to lookup some information from this file, do I always have to update value/links. Why can't excel remember the path & file name and enter information? It gets complicated because it works fine sometimes and it works always when the server file is open.

    Sorry to be a bother but I am new to excel vba and may not understand the concept.
    TIA


    Here is the actual macro:

    Sub InsertNamefromBarcode

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],\\resfiles\bioinfo\gCell\reports\prd\[CellLineReport.csv]CellLineReport!C1:C3,3,0)"

    End sub
    Last edited by sureshks; 04-30-2012 at 04:45 PM.

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Vlookup requires update links to server file everytime

    Hi Suresh,

    Excel can remember the path and file name... but since that file provides results (which can be updated at any time), hence excel need to get those results every time code (formula) is executed via those links used in VBA code (formulas)...Else how would excel can get those updated results...without referencing / updating links ...!!

    Regards,
    DILIPandey

    <click on below 'star' if this helps>


    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  7. #7
    Registered User
    Join Date
    04-13-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Vlookup requires update links to server file everytime

    Hi Dilipandey,
    Thanks for helping out. What I don't understand is this:
    1) When the source file is open, the macro runs fine, it does not ask to link or update values
    2) When it is closed, it is asking me to update/link values and it wants me to point it to the location of the folder. It is not asking me whether I want to update values, it is asking me to physically point to the file where the data is stored.

    Is there a way I can run this macro without this prompt? I don't think screenupdate=False would work because it is asking me for a file location. Is there a way I can store the path and file name so that I don't have to point to it everytime I run the macro?

    TIA
    Suresh

  8. #8
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Vlookup requires update links to server file everytime

    Yes... you can store the path which can be used further in the macro code..
    Also, as a check is the below path is starting with server name :-

    \\resfiles\bioinfo\gCell\reports\prd\[CellLineReport.csv]

    resfiles is a server name here ?

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  9. #9
    Registered User
    Join Date
    04-13-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Vlookup requires update links to server file everytime

    Yes resfiles is the server name.
    The macro works fine when the source file is open. My question is "Do we need to have the source file open for the macro to work? The source file is read only, does this have any effect?"

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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