I got this 1004 run-time error on the code below. The line I mark as comment is the key of this question. Whenever the line mark as comment this code always got 1004 run-time error. And the code works good when I put the line back as normal code. Is there anyway to skip the sheet activation during this code since that activation makes the excel jumping around during the code running.
Thank you.
Public Sub Summary_calculation()
   Dim wb As Workbook
   Dim ws As Worksheet
   Dim endrow As Integer
   Dim temprow As Integer
   Dim tempcol As Integer
   Dim i As Integer
   Dim totalrec As Integer
   Dim tmpSheet As Worksheet
   Dim SKUCol As Integer
   Dim SKUName As String
   Dim tmpSheetrow As Integer
   Dim tmpcol As Integer
   Dim tmpQty As Double
   Set wb = ActiveWorkbook
   Set ws = wb.Sheets("Summary")
   SKUCol = 3
   totalrec = ws.Cells(startrow, 1).CurrentRegion.Rows.Count - 1
   For i = 1 To totalrec
      SKUName = ws.Cells(i + startrow, SKUCol).Value
      Set tmpSheet = wb.Sheets(SKUName)
      'tmpSheet.Activate (Got 1004 error whenever remove this line of code)
      tmpSheetrow = tmpSheet.Cells(startrow, Gapcol).CurrentRegion.Rows.Count + startrow - 1
      For tmpcol = 0 To 16
         With wb.Sheets(SKUName)
            ws.Cells(i + startrow, tmpcol + 4).Value = Application.WorksheetFunction.Sum(.Range(Cells(startrow + 1, PropStartcol + tmpcol), Cells(tmpSheetrow, PropStartcol + tmpcol)))
         End With
      Next tmpcol
      ws.Cells(1, 10) = Format(i / totalrec, "00%")
      DoEvents
   Next i
End Sub
 
     
    