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:
Private Sub cmdmerge_Click() 'Open the Workbook Set wkbSource = Workbooks.Open("C:\index30052006.xls") 'Set wksSource = wkbSource.Worksheets(1) 'Set wksTarget = wkbSource.Worksheets(2) 'LastRow = wksSource.UsedRange.End(xlDown).Row Worksheets(1).Columns(1).Copy Worksheets(2).Columns(10) Worksheets(1).Columns(4).Copy Worksheets(2).Columns(6) Worksheets(1).Columns(5).Copy Worksheets(2).Columns(8) Worksheets(1).Columns(8).Copy Worksheets(2).Columns(7) Worksheets(1).Columns(9).Copy Worksheets(2).Columns(12) Worksheets(1).Columns(11).Copy Worksheets(2).Columns(9) nextstep End Sub Private Sub Matching() Rs1.Open "Select * from Category where DescriptionCategory like '" & scat & "'", cnn, adOpenStatic, adLockOptimistic If Rs1.RecordCount = 0 Then Worksheets(2).Cells(i, 2).Value = "No Value" Else Worksheets(2).Cells(i, 2).Value = Rs1!CategoryID End If Rs1.Close End Sub Private Sub nextstep() Dim lastRow As Integer lastRow = Worksheets(1).UsedRange.End(xlDown).Row For i = 2 To lastRow scat = Worksheets(1).Cells(i, 2) Matching Next i wkbSource.Save wkbSource.Close False Set wkbSource = Nothing End Sub




Reply With Quote