+ Reply to Thread
Results 1 to 7 of 7

VB Code to export data from excel to Access

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to export data from excel to Access

    Hello:

    Please refer to attached file.
    I need a VB Code to export certain data from excel to MS Access.
    I am using below code after doing google search and trying to implement however i am getting error at certain point.
    Please Login or Register  to view this content.
    Below is my requirement

    Sheet from where data is to be extracted to be exported : EmpHours
    Data Range A5 to End of month (in this case look for last day of month 11/30/2015)


    Name of Access File Test1.mdb
    Location C:\Temp\ ' This will be the same path as the excel file.
    Table Name : EmpHour2


    Let me know if you have any questions.
    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: VB Code to export data from excel to Access

    Hi Riz,

    I think it would be much easier to import excel file into Access than export from excel.

    All you have to do is to go to your Access database, External Data tab and select Excel icon, click on Browse and navigate to the location of your excel file. Select file and click Open, then Next and finish.

    I did it without any issues.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to export data from excel to Access

    Hi AllKey:

    The problem is that i have lots of workbook and in each workbook there are lots of data in different range which needs to be sent to Access for further evaluation.
    I thought exporting the data would be the best solution as the macro will define the certain data range and will define which Sheets to be used etc.
    The above code seems to error out at J=3 for some reason.
    If I can pass that error than hopefully it should work somewhat.
    Please let me know if you have any questions.
    Thanks.

    Riz

  4. #4
    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,888

    Re: VB Code to export data from excel to Access

    I concur with Alkey. I use Access extensively and it is quicker and faster to use the wizard to import data, especially if you are loading lots of different worksheets as the data ranges differ greatly. If you are repeatedly importing the same structure workbook and appending data, then and only then do I use VBA. As a side note, I always import (even when using VBA) from the Access side and not export from the Excel side. It is just easier and less demanding/confusing.

    Alternatively, you can link Excel tables to Access and they work as if the tables are resident in the Access Data Base.
    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

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to export data from excel to Access

    Hi alan:

    Thanks a lot for your reply.
    Please help me with the below.
    I have attached excel sheet.
    Here i have number of sheets.
    To start off with i need to Import data into Access table tblEmpHour as follows.
    First i need to import data from "EmpInOut" Sheet from Cell A120 down until column D with non-error data. In this case it is upto row 340.
    When i import next time, i would need to append to the same table with the same requirement, Cell A120 down until column D with non-error data.

    Please refer to attached file.
    Let me know if you have any questions.
    Thanks.

    Riz
    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,888

    Re: VB Code to export data from excel to Access

    Am traveling with only iPad for a couple of days. Will look at next week when I get home.

  7. #7
    Forum Contributor
    Join Date
    03-05-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    301

    Re: VB Code to export data from excel to Access

    Hi Riz,

    I import excel data all the time into Access. There are two primary ways I do it. The first is using the inbuilt import function in vba:

    Please Login or Register  to view this content.
    The Access table MUST contain the exact same columns as your excel sheet. It's a lot faster than any other method, but there are some severe limitations.

    Although it might be a bit slower, I almost always use an Excel to Array, Array to Access function. Where you might have multiple sheets, you can simply use loop for each sheet. Here, I get the filename from a dialogue them pass it to this function.

    Please Login or Register  to view this content.
    The Array contains the column headings. From here, you can simply use those headings to define the Access fields you want populated. Then loop the data into your table. You can also add other information into the table at the same time if you like. I almost always use an array because I want a great deal more control over the information that ends up in the table. For example, I'll use a loop like this to build information into related tables, such as ID's.

    I use the name of the sheet from which the data came to determine which table the data should go to: e.g

    Please Login or Register  to view this content.
    And loop in the array:

    Please Login or Register  to view this content.
    You should be able to figure out how to loop your data from here. It does require that you modify your code to your application, but this will give you an idea about how you can do it.

    Hope this helps

+ 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. VB Code to export data from excel to Access
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2015, 12:58 PM
  2. Export Excel Data to Access using VBA
    By RaydenUK in forum Excel General
    Replies: 0
    Last Post: 02-05-2015, 04:52 PM
  3. Error when try to export Excel data to Access
    By Nelliebeanz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-24-2014, 09:02 AM
  4. Export data from excel to Access
    By gunjanagrawal78 in forum Access Tables & Databases
    Replies: 1
    Last Post: 04-25-2014, 09:57 AM
  5. Opening Excel from Access, running Code in Excel then export back to Access
    By JungleJme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2012, 08:49 AM
  6. Replies: 0
    Last Post: 07-06-2006, 03:25 PM
  7. export data from Excel to MS Access (ADO) using VBA
    By Peter Brom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2005, 04:06 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