gỡ lỗi câu lệnh trong vba

Liên hệ QC

@1234

Thành viên mới
Tham gia
30/9/13
Bài viết
3
Được thích
0
Mình có 2 file excel khác nhau. Mình muốn viết câu lệnh vba để thực hiện nếu tìm thấy dữ liệu ở file 1 giống file 2 thì sẽ copy dữ liệu ở các cột tiếp theo ở file 1 vào file 2. Mình đang mò mẫm viết câu lệnh như sau. Nhờ các bạn góp ý giúp mình. Cảm ơn nhiều

Option Explicit
Sub COPY_DATA()
Dim i As Integer
Dim path As String
Dim filename As String
Dim wkb As Workbook
Dim lookuprange As Range

Application.ScreenUpdating = False
path = "Desktop"
filename = Dir(path & "test 01.xls", vbNormal)
Set wkb = Workbooks.Open(filename:=path & "\" & filename)
Set lookuprange = ActiveWorkbook.Sheets("Sheet1").Range("A1" & ":A" & Rows.Count)

With wkb.Sheets("SQL Results")
For i = 1 To Range("F" & Rows.Count).End(xlUp).Row
If Application.WorksheetFunction.IfNa(VLookup("F" & i, lookuprange, 1, False), 0) > 1 Then
wkb.Sheets("SQL Results").Range("I" & i & ":W" & i).Copy
Set irow = Application.WorksheetFunction.Match("A" & i, lookuprange, 0)
ActiveWorkbook.Sheets("Sheet1").Range("B" & irow & ":p" & irow).Paste
End If
Next
End With
Application.ScreenUpdating = True
End Sub
 
Web KT
Back
Top Bottom