I have a problem with my code, I am trying first to copy columns from worksheet1 to worksheet2 inside the same workbook and second i want to convert column 2 in worksheet1 which contains string into an integer column
by connecting to a database and retrieving the ID corresponding to each cell and copy the ID in the same cell but in worksheet2.Everything's ok but my problem is that I obtain the following message:
"A file named "index30052006.xls" already exists in this location.Do you want to replace it?".Can anyone help me to find what's wrong?


VB Code:
  1. Private Sub cmdmerge_Click()
  2. 'Open the Workbook
  3. Set wkbSource = Workbooks.Open("C:\index30052006.xls")
  4.  
  5.  
  6. 'Set wksSource = wkbSource.Worksheets(1)
  7. 'Set wksTarget = wkbSource.Worksheets(2)
  8.  
  9. 'LastRow = wksSource.UsedRange.End(xlDown).Row
  10.  
  11. Worksheets(1).Columns(1).Copy Worksheets(2).Columns(10)
  12. Worksheets(1).Columns(4).Copy Worksheets(2).Columns(6)
  13. Worksheets(1).Columns(5).Copy Worksheets(2).Columns(8)
  14. Worksheets(1).Columns(8).Copy Worksheets(2).Columns(7)
  15. Worksheets(1).Columns(9).Copy Worksheets(2).Columns(12)
  16. Worksheets(1).Columns(11).Copy Worksheets(2).Columns(9)
  17.  
  18. nextstep
  19. End Sub
  20.  
  21.  
  22. Private Sub Matching()
  23. Rs1.Open "Select * from Category where DescriptionCategory like '" & scat & "'", cnn, adOpenStatic, adLockOptimistic
  24. If Rs1.RecordCount = 0 Then
  25. Worksheets(2).Cells(i, 2).Value = "No Value"
  26. Else
  27. Worksheets(2).Cells(i, 2).Value = Rs1!CategoryID
  28. End If
  29. Rs1.Close
  30. End Sub
  31.  
  32. Private Sub nextstep()
  33. Dim lastRow As Integer
  34.  
  35. lastRow = Worksheets(1).UsedRange.End(xlDown).Row
  36. For i = 2 To lastRow
  37. scat = Worksheets(1).Cells(i, 2)
  38. Matching
  39. Next i
  40. wkbSource.Save
  41. wkbSource.Close False
  42.   Set wkbSource = Nothing
  43. End Sub