View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Alen32 Alen32 is offline
external usenet poster
 
Posts: 78
Default Copy from one workbook to another

I want to copy cells f,l,g from workbook bonus to workbook Destination. But
only cells from rows where column A er equal a or c.
I got this code here but doesn't work:
Sub Control()

Workbooks.Open Filename:="c:\bonus.xls"
Workbooks.Open Filename:="c:\Destination.xls"
CopyData 6, "A"
CopyData 7, "B"
CopyData 12, "C"

End Sub
Sub CopyData(col As Long, target As String)
Dim iLastRow As Long

With Workbooks("bonus.xls").Worksheets("Ark1")
iLastRow = .Cells(.Rows.Count, col).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, col).Value = "a" Or _
.Cells(i, col).Value = "c" Then

Workbooks("Destination.xls").Worksheets("Ark1").Ce lls(i, target) = _
.Cells(i, col).Value
End If
Next i
End With

End Sub