+ Reply to Thread
Results 1 to 11 of 11

Reading CSV into listobject query table

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Reading CSV into listobject query table

    Hi Guys,

    i want to do 2 things:
    1) Import CSV table in format like:

    "Col1","Col2","Col3"
    "1","2",""
    "","3","4"

    into Excel activesheet.

    2) If listobject not exists just create new listobject.

    3) If listobject exists just refresh whole table to get the same result like in CSV (for example data added, column deleted and so on).

    I tried with ADODB object :

    Please Login or Register  to view this content.
    but it failed for me - the varCsvData variant array is empty.

    and i tried this code:

    Please Login or Register  to view this content.
    but i am getting:

    Screenshot_106.png

    Maybe i could use somehow power query formula through VBA to change it dynamically and use query?
    I do not know,
    please help,
    Best Wishes,
    Jacek
    Attached Files Attached Files

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

    Re: Reading CSV into listobject query table

    The return value of a function should be the function's name, not a different variable. If you are trying to return the recordset itself, you should be using Set and assigning objRs to the return variable.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    Thank you Rory!

    I did what you seggested and have code like here:

    Please Login or Register  to view this content.
    it worked!

    But i have issues with adding this query to listobject. How can i do this?
    Tried code from here:

    Please Login or Register  to view this content.
    but it is not working for me.
    Plus code .Name = "Contact List" didnt work for me (is is Connection instead of "Contact List") (see attachemnt).

    And now checking if QT exists can be with code below?:

    Please Login or Register  to view this content.
    Best wishes,
    Jacek
    Attached Images Attached Images
    Attached Files Attached Files

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

    Re: Reading CSV into listobject query table

    Querytables created this way can't be associated with a Listobject. Why don't you just create a parameterised PQ query with a table for the CSV path?

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    Yes, so maybe i should create listobject first?

    Thank you.

    I was thinking about it but it seems to be more work - check if queries exists if not delete, refresh all connections plus i will have dynamic paths...

    In my code only listobject add query table and check if they exists.
    Can you pelase help with listobject query table add method ?

    Jacek

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

    Re: Reading CSV into listobject query table

    Why do you need a listobject specifically?

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    This will be a part of source data for me and i will be refering to tables from formulas using index,match.

    Jacek

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    Ok i think i figured this out:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    Ok but i can not close the topic yet.

    What i faced is to refresh existing QryTable:

    Please Login or Register  to view this content.
    This code: qt.Refresh BackgroundQuery:=False doesnt work.
    I mean it is not refreshable query. Why ?
    Attached Images Attached Images
    Attached Files Attached Files

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

    Re: Reading CSV into listobject query table

    If you create a query using a recordset, you can't refresh it as it isn't linked to anything. (I'm pretty sure we've had this conversation before)

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Reading CSV into listobject query table

    Thank you Rory,

    sorry - now i remember.

    But still need to know few things (the 2nd not working as i want to)

    Please Login or Register  to view this content.
    1) refreshable query with link to source - it is created only via Power Query or MS Query or do we have other possibilities?

    2) After running code i can no open csv file when Excel is opened - for sure some not released object causing it. I tried to set recordset as nothing but didnt work. How cna i do this?

    Please help,
    Best wishes for you in New Year!
    Jacek
    Jace

+ 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. Delete listobject with query table based on connection name
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2024, 07:12 PM
  2. [SOLVED] Create listobject from external query
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-26-2018, 03:18 AM
  3. [SOLVED] Copy filtered column of ListObject to another ListObject
    By snapfade in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2016, 04:00 PM
  4. ListObject SQL query not setting NumberFormat
    By cheetah05 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2014, 06:08 AM
  5. [SOLVED] Converting Query Table to ListObject
    By x10sion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2013, 06:56 AM
  6. Remove Filter From ListObject Table
    By efernandes67 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2011, 04:47 AM
  7. Table ListObject Filter
    By efernandes67 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2011, 07:40 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