Godders199
Active Member
- Joined
- Mar 2, 2017
- Messages
- 313
- Office Version
- 2013
Hello, I have the following code, which can take upto 3 minutes to run , depending on the number of rows in the spreadsheet( normally around 3000). There are two elements i am not sure off, I have read that copy paste is not the most efficient code to use, but cannot find examples of alternative solutions.
Secondly , I cannot find a way to purely copy the filtered rows and insert directly into access. you will see my current solution effectively copies into a blank spreadsheet and then access pulls the information from there.
Just looking at any code which will reduce the running time.
Sub save_allocation()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayStatusBar = False
Application.EnableEvents = False
' Allocationdump Macro
'Dim xm As Long
'
Sheets("submissions").Select
If Sheets("submissions").FilterMode Then Sheets("submissions").ShowAllData
Cells.Select
ActiveSheet.Range("A:ac").AutoFilter Field:=18, Criteria1:="<>"
Range("a2:z2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Open Filename:= _
"S:\4th Floor\SQ Operations\OPs Mi Spreadsheets\Allocation audit tools\2018\history.xlsx"
Range("a1").Select
xm = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("a" & xm).PasteSpecial xlPasteValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Sheets("submissions").ShowAllData
Sheets("instructions").Select
'add allocated cases to access'
Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
appAccess.opencurrentdatabase "S:\4th Floor\SQ Operations\OPs Mi Spreadsheets\Allocation audit tools\2018\Allocation history1.accdb"
appAccess.Visible = False
appAccess.Run "importexcelspreadsheet"
appAccess.Quit
Set appAccess = Nothing
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub
Secondly , I cannot find a way to purely copy the filtered rows and insert directly into access. you will see my current solution effectively copies into a blank spreadsheet and then access pulls the information from there.
Just looking at any code which will reduce the running time.
Sub save_allocation()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayStatusBar = False
Application.EnableEvents = False
' Allocationdump Macro
'Dim xm As Long
'
Sheets("submissions").Select
If Sheets("submissions").FilterMode Then Sheets("submissions").ShowAllData
Cells.Select
ActiveSheet.Range("A:ac").AutoFilter Field:=18, Criteria1:="<>"
Range("a2:z2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Workbooks.Open Filename:= _
"S:\4th Floor\SQ Operations\OPs Mi Spreadsheets\Allocation audit tools\2018\history.xlsx"
Range("a1").Select
xm = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("a" & xm).PasteSpecial xlPasteValues
ActiveWorkbook.Save
ActiveWorkbook.Close
Sheets("submissions").ShowAllData
Sheets("instructions").Select
'add allocated cases to access'
Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
appAccess.opencurrentdatabase "S:\4th Floor\SQ Operations\OPs Mi Spreadsheets\Allocation audit tools\2018\Allocation history1.accdb"
appAccess.Visible = False
appAccess.Run "importexcelspreadsheet"
appAccess.Quit
Set appAccess = Nothing
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub