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
Private Sub tbDG_Change() | |
If Me.tbDG = "" Or Me.tbSL = "" Then Exit Sub | |
If Me.tbSL >= 0 And Me.tbDG >= 0 Then Me.tbTT = Me.tbSL * Me.tbDG | |
End Sub |
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
Private Sub tbSL_Change() | |
If Me.tbSL = "" Or Me.tbDG = "" Then Exit Sub | |
If Me.tbDG >= 0 And Me.tbSL >= 0 Then Me.tbTT = Me.tbDG * Me.tbSL | |
End Sub |
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 Gop_Sheet() 'Câu lệnh gộp nhiều file Excel vào 1 file | |
'Câu lệnh này đặt trong file Tổng hợp chi nhánh | |
Path = "C:\Users\Quan\Desktop\Report\" 'Đây là đường dẫn tới thư mục chứa file | |
Filename = Dir(Path & "*.xlsx") 'Khi mở đường dẫn thì chúng ta sẽ chọn các file trong đường dẫn đó | |
Do While Filename <> "" 'Thực hiện câu lệnh này khi có file trong thư mục (tránh lỗi không có file) bằng vòng lặp | |
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True 'Mở các file trong thư mục | |
For Each Sheet In ActiveWorkbook.Sheets 'Với mỗi Sheet có trong file chi nhánh sẽ thực hiện việc copy | |
Sheet.Copy After:=ThisWorkbook.Sheets(1) 'Câu lệnh copy sheet sang file Tổng hợp | |
Next Sheet 'Tiếp tục thực hiện thao tác trên với file khác | |
Workbooks(Filename).Close 'Đóng các file chi nhánh |
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 Transpose_Range() | |
Dim i As Long | |
Dim SoDong As Integer 'Độ rộng của mỗi nhóm = số dòng | |
SoDong = 4 | |
With [A1:D17] 'Vùng cần transpose | |
For i = 2 To [A65536].End(xlUp).Row Step SoDong 'Thực hiện việc copy theo từng nhóm dựa vào số dòng | |
Union(.Rows(i), .Rows(i).Resize(SoDong)).Copy 'Vùng cần copy từ dòng i tới dòng cuối trong nhóm đó | |
Sheet1.Range("A" & Rows.Count).End(xlUp)(1).PasteSpecial Transpose:=True 'Nơi dán kết quả transpose | |
Next |
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 PrintArea_Test04() 'Vùng in theo vùng được chọn | |
Sheet1.PageSetup.PrintArea = Selection.Address | |
End Sub |
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 PrintArea_Test03() 'Thiết lập vùng in tới dòng cuối | |
Sheet1.PageSetup.PrintArea = Sheet1.Range("B2", sheet1.Range("G" & rows.count).End(xlUp)).Address | |
End Sub |
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 PrintArea_Test02() 'Thiết lập vùng in tới dòng cuối | |
Sheet1.PageSetup.PrintArea = Sheet1.Range("B2", Sheet1.Range("G65536").End(xlUp)).Address | |
End Sub |
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 PrintArea_Test01() 'Thiết lập vùng in từ B2:G100 tại Sheet1 | |
Sheet1.PageSetup.PrintArea = Sheet1.Range("B2:G100").Address | |
End Sub |
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 FIFO_VBA() 'Tính giá xuất kho theo FIFO | |
Dim SL_Xuat As Long 'Thiết lập biến xác định số lượng cần xuất | |
Dim i As Integer 'Biến i chạy trong vòng lặp xét lần Xuất | |
Dim j As Integer 'Biến j chạy trong vòng lặp xét số lượng xuất dựa trên số đã nhập | |
Dim SL_Cac_Lan_Nhap As Long 'Số lượng các lần nhập xét theo FIFO | |
Dim TT_Xuat As Double 'Giá trị xuất kho = Thành tiền | |
Dim cot_SL_Nhap As Variant 'Thiết lập biến Cột số lượng nhập | |
Dim cot_DG_Nhap As Variant 'Thiết lập biến Cột đơn giá nhập | |
Range("I3:I1000").ClearContents 'Làm mới cột kết quả giá trị xuất kho tính bằng FIFO / cột I |
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
Private Sub ComboBox2_Change() 'Sự kiện thay đổi danh sách tại ComboBox3 theo giá trị được chọn tại ComboBox2 | |
Dim rng As Range 'Tạo biến Vùng danh sách gốc | |
Dim r As Range 'Tạo biến để thực hiện vòng lặp giúp kiểm tra danh sách nạp vào ComboBox2 | |
Dim Dic As Object 'Tạo biến thư viện để gọi đối tượng dictionary | |
Dim ws As Worksheet ' Tạo biến Sheet chứa danh sách gốc | |
Set ws = ActiveSheet 'Sheet chứa danh sách gốc là sheet đang làm việc (khi combobox đặt trong Sheet danh sách) | |
'Nếu khác combobox đặt tại sheet khác thì cần tham chiếu tới sheet chứa danh sách gốc | |
'*** | |
Set rng = ws.Range("B2", ws.Range("B" & Rows.Count).End(xlUp)) 'Vùng danh sách gốc ở cột B, từ ô B2 tới dòng cuối có dữ liệu |