Last active
July 31, 2018 04:25
-
-
Save DuongAQ/c598a76bbd4f53442dfdea4294c7e4db 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 Ma_Huyen_GetData() 'Lọc danh sách Quận/Huyện theo giá trị tỉnh/TP được chọn | |
Sheet1.Range("D2:D1000").ClearContents 'Làm mới danh sách | |
'Thiet lap cac bien | |
Dim vl01 As Integer 'Biến vòng lặp mã tỉnh/tp | |
Dim MaTinh As String 'Vị trí ô mã tỉnh/tp được chọn | |
MaTinh = Sheet1.Range("F1").Value | |
Dim lr_Tinh As Long | |
Dim lr_Huyen As Long | |
lr_Tinh = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row 'Dòng cuối của danh sách tỉnh/tp. Đây là giới hạn cho vòng lặp | |
lr_Huyen = Sheet1.Cells(Rows.Count, 4).End(xlUp).Row 'Dòng cuối của cột kết quả, là vị trí sẽ đưa kết quả vào | |
'Thực hiện vòng lặp | |
For vl01 = 2 To lr_Tinh | |
If MaTinh = Sheet1.Cells(vl01, 1).Value Then 'Xét mã tỉnh tại ô F1 với từng giá trị tại cột A | |
Sheet1.Cells(lr_Huyen + 1, 4).Value = Sheet1.Cells(vl01, 2).Value 'Mỗi kết quả đúng sẽ trả về giá trị tại cột D, vị trí dòng cuối + 1 là dòng trống tiếp theo phía dưới | |
lr_Huyen = Sheet1.Cells(Rows.Count, 4).End(xlUp).Row 'Sau mỗi kết quả thu được sẽ tính lại dòng cuối để lấy thêm kết quả | |
End If | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment