Created
January 17, 2018 06:52
-
-
Save DuongAQ/e0c8eff9a49d6955c0dd0dbc90c42873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Spinner_getData() | |
Dim ws As Worksheet 'Thiết lập biến ws là Sheet đang mở | |
Set ws = ActiveSheet | |
Dim rngData As Range 'Thiết lập vùng bảng dữ liệu bắt đầu từ ô D3 | |
Set rngData = Range(ws.Range("D3").End(xlDown), ws.Range("D3").End(xlToRight)) | |
Dim Data As Variant 'Xét nội dung trong bảng Dữ liệu | |
Data = rngData.Value | |
Dim iCell As Integer 'Vị trí kết quả Spinner | |
iCell = ws.Range("M2").Value | |
On Error Resume Next 'Nếu xảy ra lỗi thì bỏ qua | |
Dim tbl As ListObject 'Gán biến cho đối tượng TableTest | |
Set tbl = ws.ListObjects("TableTest") | |
tbl.DataBodyRange.Delete 'Xóa dữ liệu cũ trong Table | |
For x = LBound(Data) To UBound(Data) 'Xét vòng lặp trong vùng dữ liệu Data, từ dòng đầu tới dòng cuối của bảng | |
If iCell = Data(x, 3) Then 'Nếu kết quả Spinner bằng với kết quả của cột Thứ tự cột (cột 3 của bảng Data) | |
With tbl.ListRows.Add 'Lấy dữ liệu vào Table | |
.Range(, 2).Value = Data(x, 1) 'Lấy dữ liệu cột Tên hàng | |
.Range(, 3).Value = Data(x, 2) 'Lấy dữ liệu cột Số lượng | |
End With | |
End If | |
Next | |
tbl.DataBodyRange.AutoFit 'Tự chỉnh độ rộng của Table | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment