Excel Macro to import data in a sheet to an Access Table

Slomaro2000

Board Regular
Joined
Jun 4, 2008
Messages
107
Hello,
I need help appending data in an excel sheet (180,000 plus rows) to an Access table.

I have the following code that works for small amounts but when I try to get a large range it does not work.


Any help on this?


Code:
Option Explicit

Sub ImportToAccess()
    Dim ACC As New Access.Application
    Dim LastRow As Long
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        End With
    ACC.OpenCurrentDatabase "\\path to Access\Database.accdb"   'Intan put the path to the ACCESS Database Here  -  Below is "TableName" that will need to match the table in ACCESS (Should be correct).
    ACC.DoCmd.TransferSpreadsheet _
            TransferType:=acImport, _
            SpreadSheetType:=acSpreadsheetTypeExcel12Xml, _
            TableName:="AccessTableNameHere", _
            Filename:=Application.ActiveWorkbook.FullName, _
            HasFieldNames:=True, _
            Range:="ExcelSheetNameHere$A1:O" & LastRow
    ACC.CloseCurrentDatabase
    ACC.Quit
    Set ACC = Nothing
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,216,109
Messages
6,128,875
Members
449,476
Latest member
pranjal9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top