+ Reply to Thread
Results 1 to 9 of 9

populate a table using row and column headers

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    30

    Question populate a table using row and column headers

    Hi
    I'm trying to populate a table with data from a csv file where the first column is the row header and the second column is the column header and the third column is the data for the table

    I have managed to get the information into the table but only using the row headers so the column data does not go where it is supposed to i have added the files i'm using for you to see.
    The .csv file is just opened by the user select all and copy into clipboard at the moment but i would also like the macro to do this for me too eventually so any help there would be appreciated too
    then click the import button on the worksheet

    Averages.xlsm

    GAZ1.csv

    also because there are duplicate row/column entries but updated values i need it to only use the latest values or overwrite the values as it goes through the file
    Last edited by garywilson4; 03-05-2012 at 10:44 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: populate a table using row and column headers

    This macro will do it if the CSV file is pasted into a new sheet called CSV

    Please Login or Register  to view this content.
    Please note that the names of the fields do need to be identical

    Canon <> Cannon
    MapPart <> Map Part
    Martin

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: populate a table using row and column headers

    thanks for the reply but i am completely new to vba excel etc where do i paste the code you have given me? in a module on its own? or in with the module a already have? i tried it on its own in a module and got an error message "Run-time Error '91': Object Variable or with block variable not set"

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: populate a table using row and column headers

    If you put it in a standard module (a current or new one), you'll have to specify the worksheet for each object in the code, e.g. "Sheets("TradeAverages").Columns(1)...." instead of just "Columns(1)...". Try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-08-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: populate a table using row and column headers

    get same error i'm afraid

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: populate a table using row and column headers

    I believe that the error that you are seeing is that you do not have matching values in your sheet and CSV file and therefore the code is objecting when it can't find a match.

    I put a couple of examples in my original reply - there may be more.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: populate a table using row and column headers

    Hi
    Been following this Thread developing my own code. I believe mrice is correct
    that the error that you are seeing is that you do not have matching values in your sheet and CSV file
    The code provided appears to work with these modifications
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: populate a table using row and column headers

    Hi garywilson4

    There is a way to overcome this
    that the error that you are seeing is that you do not have matching values in your sheet and CSV file
    If you're interested, I'll work on it. It's really an issue of which comes first, the Cart or the Horse. Is CSV the Source for TradeAverages such that they MUST match or is TradeAverages getting it's data from CSV and if they don't match, such is life, no data will be shown?

  9. #9
    Registered User
    Join Date
    02-08-2012
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: populate a table using row and column headers

    Thank you all for your help it was because i had forgot to rename the fields to match the csv file exactly its working perfectly for me now

+ 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