Em mới tập mầy mò VBA. Trong quá trình làm báo cáo cho công ty em có sử dụng đoạn code sau. Múc đích là để lấy dữ liệu từ 1 bảng tham chiếu trên 1 file excel khác để cho lắp vào bản báo cáo của công ty.
Tuy nhiên đoạn code ko thực hiện được, lỗi báo tại dòng
Cells(u, 7) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 3, False), 0) (lỗi 1004, WorksheetFunction Vloop ko thể thực hiện được). (đoạn code em post ở phía dưới)
Mong các anh chỉ giúp cho em với
Sub Market_Segment()
Windows("msgm_m_15.xlsx").Activate
Sheets(1).Activate
Dim table2015 As Range
Set table2015 = Range("A5:O300")
Windows("msgm_mtd_15.xlsx").Activate
Sheets(1).Activate
Dim table2014 As Range
Set table2014 = Range("A5:O300")
Windows("BSC Report November 2015 FSH.xlsm").Activate
Sheets("5.S&M").Activate
Dim u As Integer
For u = 39 To 60
Cells(u, 7) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 3, False), 0)
Cells(u, 8) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 6, False), 0)
Cells(u, 11) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2014, 3, False), 0)
Cells(u, 12) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2014, 6, False), 0)
Next
End Sub
Tuy nhiên đoạn code ko thực hiện được, lỗi báo tại dòng
Cells(u, 7) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 3, False), 0) (lỗi 1004, WorksheetFunction Vloop ko thể thực hiện được). (đoạn code em post ở phía dưới)
Mong các anh chỉ giúp cho em với
Sub Market_Segment()
Windows("msgm_m_15.xlsx").Activate
Sheets(1).Activate
Dim table2015 As Range
Set table2015 = Range("A5:O300")
Windows("msgm_mtd_15.xlsx").Activate
Sheets(1).Activate
Dim table2014 As Range
Set table2014 = Range("A5:O300")
Windows("BSC Report November 2015 FSH.xlsm").Activate
Sheets("5.S&M").Activate
Dim u As Integer
For u = 39 To 60
Cells(u, 7) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 3, False), 0)
Cells(u, 8) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2015, 6, False), 0)
Cells(u, 11) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2014, 3, False), 0)
Cells(u, 12) = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(Cells(u, 6), table2014, 6, False), 0)
Next
End Sub