+ Reply to Thread
Results 1 to 7 of 7

Thread: Copy/Paste Excel data into Access

  1. #1
    Registered User
    Join Date
    01-17-2005
    Posts
    28

    Copy/Paste Excel data into Access

    Hi,

    How do I copy/paste data from my Excel spreadsheet into Access? When I copy a range of cells from Excel then paste it into Access, the pasted data is shifted by 1 column to the left so that my first column (dates) from Excel is not imported and all my newly pasted data is under the wrong heading. Do I need to add an extra first column to my excel spreadsheet as an "ID" column?

    Historically I've just been using the import function on Access but it seems to take a long time so I'm just trying this method.

    Thanks,

    Jason

  2. #2
    Valued Forum Contributor
    Join Date
    12-14-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    986

    Re: Copy/Paste Excel data into Access

    It is better to import data to MS Access than copy/paste
    To thank someone who has helped you, click on the star icon below their name.

    I hate reading

    Portfolio

    I need a job.
    I am young and incompetent

  3. #3
    Registered User
    Join Date
    01-17-2005
    Posts
    28

    Re: Copy/Paste Excel data into Access

    Thanks for the reply.

    Is there anything I can do to make an import faster? It will take me a few minutes to open data from the spreadsheet in Access, then another few minutes to import the data into Access... I have to do this every day for a few spreadsheets so it drives me nuts just waiting so long for a spreadsheet that may have up to 70 rows? It just seems to me like it shouldn't take so long!

    Jason

  4. #4
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Copy/Paste Excel data into Access

    If you automate the import using VBA it should take no longer than 5 seconds at the very most.

    Here is some generic code that clears a table, then imports new data into it from Excel:


    Private Sub btnImportLngExtract_Click()
    'The purpose of this procedure is to import the Long Extract that was run out of UniFi.
    
        'Declare local variables.
        Dim strFileName As String: strFileName = "C:\Temp\yourfile.xls"
        
        'Turn off warnings so the user isn't asked about record changes.
        DoCmd.SetWarnings False
        'First clear out the table of all the old data.
        DoCmd.RunSQL "DELETE * FROM tbl_LongExtract_Data"
        'Import the new data.
        DoCmd.TransferText acImportDelim, "Longextract Import Specification", "tbl_LongExtract_Data", strFileName, True
    
        'Turn warnings back on.
        DoCmd.SetWarnings True
    
    End Sub
    You should be able to modify this for your purposes.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  5. #5
    Forum Guru Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    Excel 2010
    Posts
    1,249

    Re: Copy/Paste Excel data into Access

    This is because you are probably also selecting the ID field (either because you selected the entire row in Access, or because you selected the ID field manually).

    In access, on the "New" record row, hover your mouse on left-hand side of the first field after ID. It should turn into a fat, white plus sign. Click and drag to the right the same number of columns you are copying from excel.

    Then paste. It should put the first copied column from excel into the first selected column in Access.

  6. #6
    Registered User
    Join Date
    01-17-2005
    Posts
    28

    Re: Copy/Paste Excel data into Access

    Thanks Dave, just a quick question regarding the VBA code. Why would using the VBA code only take 5 seconds to import but if I manually do it, it will take minutes?

    Thanks for the suggestion Whizbang, put your way works if I am pasting 1 row but I often have many rows to paste.

  7. #7
    Registered User
    Join Date
    01-17-2005
    Posts
    28

    Re: Copy/Paste Excel data into Access

    I think I figured out my problem. I was trying to import a spreadsheet that contained formulas with cell references and was part of a workbook with lots of other formulas and numbers in it. I just copied and pasted the values that I wanted into a new Excel workbook and imported that into Access and it was super fast.

    Thanks for all your help!

+ 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.2.0