Hi guys,
I've Tightened up the code to the best of my ability, any more suggestions speed things up?
Private Sub btnNewData_Click()
Dim xldcdata As Object
Application.Calculation = xlCalculationManual
frmworking.Show (0)
DoEvents
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("\\path\excelbook.xls")
Set xldcdata = xlBook.Worksheets("Data")
scandown = 6
HoldSelectedTime = Sheet2.Cells(8, 5) - 1
firstcheck = 0
Do
scandown = scandown + 1
holdlisttime = Left(xldcdata.Cells(scandown, 1), 10)
If holdlisttime = HoldSelectedTime Then
If firstcheck = 0 Then
checkblank = 1
Do
checkblank = checkblank + 1
Loop Until Sheet4.Cells(checkblank, 1) = ""
firstcheck = 1
Else
checkblank = checkblank + 1
End If
leftcell = "A" & scandown
rightcell = "E" & scandown
pastetocells = "A" & checkblank
Sheet4.Range(pastetocells & ":E" & checkblank - 1).Value = xldcdata.Range(leftcell, rightcell).Value
End If
Loop Until firstcheck = 1 And holdlisttime <> HoldSelectedTime
xlApp.DisplayAlerts = False
xlApp.Quit
Sheet4.Activate
'Remove Time
Sheet4.Range("A:A").Replace What:=" *", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Remove dups
Sheet4.Range("C:C").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Sheet4.Range("A1:E1").Select
Sheet4.Range(Selection, Selection.End(xlDown)).Select
Selection.copy
'Paste Data
Sheet1.Activate
Dim lRow As Long
lRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Sheet1.Paste Destination:=Sheet1.Cells(lRow, 1)
'clear imported work from temp sheet4
Sheet4.ShowAllData
Sheet4.Cells.ClearContents
Sheet2.Activate
xlApp.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
frmworking.Hide
End Sub
Thanks
I've Tightened up the code to the best of my ability, any more suggestions speed things up?
Private Sub btnNewData_Click()
Dim xldcdata As Object
Application.Calculation = xlCalculationManual
frmworking.Show (0)
DoEvents
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("\\path\excelbook.xls")
Set xldcdata = xlBook.Worksheets("Data")
scandown = 6
HoldSelectedTime = Sheet2.Cells(8, 5) - 1
firstcheck = 0
Do
scandown = scandown + 1
holdlisttime = Left(xldcdata.Cells(scandown, 1), 10)
If holdlisttime = HoldSelectedTime Then
If firstcheck = 0 Then
checkblank = 1
Do
checkblank = checkblank + 1
Loop Until Sheet4.Cells(checkblank, 1) = ""
firstcheck = 1
Else
checkblank = checkblank + 1
End If
leftcell = "A" & scandown
rightcell = "E" & scandown
pastetocells = "A" & checkblank
Sheet4.Range(pastetocells & ":E" & checkblank - 1).Value = xldcdata.Range(leftcell, rightcell).Value
End If
Loop Until firstcheck = 1 And holdlisttime <> HoldSelectedTime
xlApp.DisplayAlerts = False
xlApp.Quit
Sheet4.Activate
'Remove Time
Sheet4.Range("A:A").Replace What:=" *", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Remove dups
Sheet4.Range("C:C").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Sheet4.Range("A1:E1").Select
Sheet4.Range(Selection, Selection.End(xlDown)).Select
Selection.copy
'Paste Data
Sheet1.Activate
Dim lRow As Long
lRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Sheet1.Paste Destination:=Sheet1.Cells(lRow, 1)
'clear imported work from temp sheet4
Sheet4.ShowAllData
Sheet4.Cells.ClearContents
Sheet2.Activate
xlApp.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
frmworking.Hide
End Sub
Thanks