I have a problem with my coding when wants to move all the data to the second worksheet. I try to change the setting to make the output in 2nd worksheet, but it didnt work.

this is my code:
VB Code:
  1. Set objExcel = CreateObject("excel.application") 'Starts the Excel Session
  2. Set objBook = objExcel.Workbooks.Add             'Add a Workbook
  3. Set objSheet = objBook.Worksheets.Item(1)        'Select a Sheet
  4. objExcel.Application.Visible = True
  5.  
  6.  
  7. objExcel.Application.Cells(1, 1).Value = "Kod Kategori BA"
  8. objExcel.Application.Cells(1, 2).Value = "No.BA"
  9.  
  10.  
  11. With objExcel
  12.            
  13.             .Application.Cells(n, 1).Value = ((Trim(DataHRMIS.Recordset.Fields("BACatCd").Value)))
  14.             .Application.Cells(n, 2).Value = ((Trim(DataHRMIS.Recordset.Fields("BANo").Value)))
  15.  
  16. end with

i try to change here, but it still dont work!

VB Code:
  1. Set objSheet = objBook.Worksheets.Item(2)

how can i fix this? anyone plz help me...tq