Có phải là anh mới chỉ xử lý cái chọn danh sách mã phải không ạ? Em thấy thế là đúng ý em rồi anh ạ. Giờ anh xử lý giúp em cái phần chọn ngày nữa nhé. Em cảm ơn ạ
Hoàn chỉnh theo yêu cầu của bạn, mình có điều chỉnh dòng điều kiện lọc ngày lên trên cho hợp lý hơn.
[GPECODE=sql]Sub LocData()
Dim adoConn As Object, adoRS As Object
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
With adoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
.Open
End With
With adoRS
.ActiveConnection = adoConn
.Open "select * from [DATA$A2:F10000] " _
& "where F2 like '" & Sheet1.Range("B3").Value & "' and " _
& "F1 between #" & Format(DateSerial(Year(Sheet1.[B2]), Month(Sheet1.[B2]), Day(Sheet1.[B2])), "mm/dd/yyyy") _
& "# AND #" & Format(DateSerial(Year(Sheet1.[d2]), Month(Sheet1.[d2]), Day(Sheet1.[d2])), "mm/dd/yyyy") & "# "
End With
With Sheet1
.[A6:F10000].ClearContents
.[A6].CopyFromRecordset adoRS
End With
adoRS.Close: Set adoRS = Nothing
adoConn.Close: Set adoConn = Nothing
End Sub
Sub LocTop50()
LocDuyNhat
Dim adoConn As Object, adoRS As Object
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
With adoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
.Open
End With
With adoRS
.ActiveConnection = adoConn
.Open "select * from [DATA$A2:F10000] " _
& "where F2 like '" & Sheet1.Range("i3").Value & "' and " _
& "F1 between #" & Format(DateSerial(Year(Sheet1.[i2]), Month(Sheet1.[i2]), Day(Sheet1.[i2])), "mm/dd/yyyy") _
& "# AND #" & Format(DateSerial(Year(Sheet1.[k2]), Month(Sheet1.[k2]), Day(Sheet1.[k2])), "mm/dd/yyyy") & "# "
End With
With Sheet1
.[H6:M10000].ClearContents
.[H6].CopyFromRecordset adoRS
End With
adoRS.Close: Set adoRS = Nothing
adoConn.Close: Set adoConn = Nothing
End Sub
Sub LocDuyNhat()
Dim adoConn As Object, adoRS As Object
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
With adoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & _
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
.Open
End With
With adoRS
.ActiveConnection = adoConn
.Open "select distinct f2 " _
& "from [DATA$A2:F10000] " _
& "where F2 is not null "
End With
With Sheet2
.[B2:B10000].ClearContents
.[B2].CopyFromRecordset adoRS
.Range("B2:B" & .[B65500].End(xlUp).Row).Name = "MaCK"
End With
adoRS.Close
With adoRS
.ActiveConnection = adoConn
.Open "select distinct f1 " _
& "from [DATA$A2:F10000] " _
& "where F1 is not null" ' and f2 like '" & Sheet1.Range("B2").Value & "'"
End With
With Sheet2
.[C2:C10000].ClearContents
.[C2].CopyFromRecordset adoRS
.Range("C2:C" & .[C65500].End(xlUp).Row).Name = "Ngay"
End With
adoRS.Close: Set adoRS = Nothing
adoConn.Close: Set adoConn = Nothing
End Sub
[/GPECODE]