+ Reply to Thread
Results 1 to 10 of 10

Dynamically create headers in Excelsheet using Access table values

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Dynamically create headers in Excelsheet using Access table values

    Hi guys

    I have an access table and I want the code that will check two columns in the table "EnvelopeType" and "EnvelopeSize" and create headers in Excelsheet automatically. In the attached workbook, like in sheet1 the headers are already appeared,, I want this to be done dynamically using vba code so that if new values get inserted in EnvelopeType and EnvelopeSize then we won't have to change the code to display more headers.

    Please see attached workbook named Sample and as i can't upload Access table so I have exported it in Excel to give you an idea how my Access table looks like. But in the code we have to make a connection with Access table and getvalues from EnvelopeType and EnvelopeSize to display hearders in the excelsheet.

    e.g EnvelopeType EnvelopeSize
    TNT 2nd Class C5
    PP1 2nd Class C5
    PPI 1st Class A4
    Recorded A4
    TNT 2nd Class C5
    PP1 2nd Class C5
    Recorded A4
    PPI 1st Class A4
    Recorded C5


    With the code it should display following headers in excelsheet:

    TNT 2nd Class C5
    PP1 2nd Class C5
    PPI 1st Class A4
    Recorded A4
    Recorded C5

    Any help would be much appreciated.

    Thanks
    Attached Files Attached Files
    Last edited by aman1234; 04-02-2014 at 06:35 AM.

  2. #2
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    Can anyone please help me to do this?

    its very urgent to resolve so please guys give me ur ideas.

    Thanks

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Dynamically create headers in Excelsheet using Access table values

    Here is an alternative solution:

    Create an aggregate query in Access and export it directly to Excel

    Here is the SQL statement for the Aggregate Query

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by alansidman; 04-02-2014 at 09:04 AM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    Thanks. The following code works fine in displaying the headers in the excelsheet. so attached is the excelsheet with the headers in rows and columns. Now I want to display the sum(volume) for each month matching with the EnvelopeType and Envelope Size in the column headers.

    Please could you help me in this?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    Thanks alansidman

    The query displays the right result but Now how to display the output in the right way as in attached sheet and how to export it on the click event of a button?

    Thanks
    Attached Files Attached Files

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Dynamically create headers in Excelsheet using Access table values

    You can export using the TransferSpreadsheet vba function in Access or use the built in Export Wizard. Then you can cut and pastespecial transpose to get it to look like you wish in excel

    Edit: You could also use the exported data to make a Pivot Table.
    Last edited by alansidman; 04-02-2014 at 12:05 PM.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Dynamically create headers in Excelsheet using Access table values

    Here's a PT created from the query.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    Hi alansidman

    The pivot table looks great but when I add more data in Query1 sheet then it doesn't appear in pivot table. Any suggestions?

    Many thanks for your help so far.

    Aman

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    hi alansidman

    I am writing the following code to export the query result from Access to Excel. but how to create pivot table of that data using vba code.
    Please Login or Register  to view this content.
    Thanks

  10. #10
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Dynamically create headers in Excelsheet using Access table values

    The following code works perfectly fine. now I just want to add one more condition in this i.e Display those results only where EnvelopeSource='Elevate Bulk'
    Please Login or Register  to view this content.
    Can you please help me in this.
    Thanks

+ 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. Extract data from Access table into excelsheet
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2012, 05:36 AM
  2. Link excelsheet with access table using vba
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2011, 05:18 AM
  3. Transfer data from excelsheet to access table
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2011, 04:35 AM
  4. Transfer data from Access table to Excelsheet
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 03:38 AM
  5. Display the result in excelsheet from Access table
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2009, 06:52 PM

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