Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DuongAQ
Created March 5, 2018 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuongAQ/eef1120379691285f2b147b87c392681 to your computer and use it in GitHub Desktop.
Save DuongAQ/eef1120379691285f2b147b87c392681 to your computer and use it in GitHub Desktop.
Sub OpenImp3() 'Lấy nội dung từ 1 vùng xác định
Const sPath="C:\Test\" 'Đường dẫn tới thư mục
Dim sFil As String
Dim owb As Workbook
Dim ws As Worksheet
Dim lr as long
Set ws=Sheet1
sFil=Dir(sPath & "*.xl*")
Do While sFil <> ""
Set owb=Workbooks.Open(sPath & sFil) 'Mở workbook cần lấy nội dung
'Lọc nội dung cần lấy trong vùng từ A1 tới dòng cuối cột F, giá trị lọc là England ở cột A
Range("A1", Range("F" & Rows.Count).End(xlUp)).AutoFilter Field:=1, Criteria1:="England"
'Nếu có kết quả lọc thì copy dữ liệu
lr=Range("F" & Rows.Count).End(xlUp).Row
If lr > 1 Then Range("A2", Range("F" & Rows.Count).End(xlUp)).Copy ws.Range("A" & Rows.Count).End(xlUp)(2)
'Đóng workbook đã mở, không lưu file
owb.Close False
sFil=Dir
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment