giải thích code tính số lượng tồn

Liên hệ QC

Rùa Con 1080

Thành Viên Sao Chép 2
Tham gia
4/5/16
Bài viết
351
Được thích
47
Giới tính
Nữ
Mong bạn HYen17 giải thích dùm mình code tính số lượng tồn mà bạn đã làm giúp mình, để mình học hỏi với.
Mã:
[COLOR=#0000BB][FONT=monospace]Sub TinhTNX[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Byte[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dim Sh [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Worksheet[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range
 Dim ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]String[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]MyAdd [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]String
 Dim Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Integer
 
 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Ton"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                             [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0
 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]ElseIf [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Nhap"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                            [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1
 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]ElseIf [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Xuat"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                            [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3
 End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set Sh [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ThisWorkbook[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Worksheets[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ShName[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set Rng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Sh[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Columns[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"A:A"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Offset[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Find[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Me[/FONT][/COLOR][COLOR=#007700][FONT=monospace]![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]tb_TPL[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Text[/FONT][/COLOR][COLOR=#007700][FONT=monospace], , [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlFormulas[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlWhole[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Not sRng Is Nothing Then
1    MyAdd [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Address
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]Do
        [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]+ [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]IIf[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3[/FONT][/COLOR][COLOR=#007700][FONT=monospace], -[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) * [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Offset[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Value
        Set sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]FindNext[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]5    Loop [/FONT][/COLOR][COLOR=#007700][FONT=monospace]While [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Not sRng Is Nothing [/FONT][/COLOR][COLOR=#007700][FONT=monospace]And [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Address [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]MyAdd
 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]Else
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End Sub  [/FONT][/COLOR]

File đây
 
Mã:
[COLOR=#0000BB][FONT=monospace]Sub TinhTNX[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Byte[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dim Sh [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Worksheet[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Range
 Dim ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]String[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]MyAdd [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]String
 Dim Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Integer
 
1 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Ton"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                             [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0
3 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]ElseIf [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Nhap"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                            [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1
5 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]ElseIf [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Col [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3 Then
    ShName [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Xuat"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]:                            [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3
7 End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set Sh [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ThisWorkbook[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Worksheets[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ShName[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
9 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set Rng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Sh[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Columns[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"A:A"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Offset[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Set sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Find[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Me[/FONT][/COLOR][COLOR=#007700][FONT=monospace]![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]tb_TPL[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Text[/FONT][/COLOR][COLOR=#007700][FONT=monospace], , [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlFormulas[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]xlWhole[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
11 If [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Not sRng Is Nothing Then
    MyAdd [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Address
13    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]Do
        [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]SL [/FONT][/COLOR][COLOR=#007700][FONT=monospace]+ [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]IIf[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Cot [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]3[/FONT][/COLOR][COLOR=#007700][FONT=monospace], -[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) * [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Offset[/FONT][/COLOR][COLOR=#007700][FONT=monospace](, [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Value
15        Set sRng [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Rng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]FindNext[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]    Loop [/FONT][/COLOR][COLOR=#007700][FONT=monospace]While [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Not sRng Is Nothing [/FONT][/COLOR][COLOR=#007700][FONT=monospace]And [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sRng[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Address [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]MyAdd
17 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]Else
 [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End [/FONT][/COLOR][COLOR=#007700][FONT=monospace]If
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End Sub  [/FONT][/COLOR]


Phải nói trước rằng đây là macro cần được cung cấp 1 tham biến kiểu Byte (Col); Tùy thuộc vô tham biến mà nó sẽ chọn hướng đi thích hợp để cho ra kết quả khác nhau

3 dòng lệnh trên dòng 1: Khai báo các biến cần dùng;
D1: Đ/K nếu tham biến được cung cấp là 1 thì thực hiện câu lệnh tiếp ngay sau;
D2: Mệnh đề 1: Lấy chuỗi 'Ton' (thực ra là tên trang tính) gán vô biến đã khai báo;
Mệnh đề sau: Ấn định giá trị cho 1 biến đã khai báo tương ứng với tham biến đã nhận do macro cha/mẹ cung cấp.

(Các dòng lệnh 3 & 4 hay 5 & 6 cũng tương tự cách giải thích trên; Chỉ khác đi các giá trị gán vô các biến tương ứng)
D7: Kết thúc Đ/K
(Thực ra nếu muốn gọn ta gôm 7 dòng lệnh này thành 2 câu lệnh; Nhưng lúc đó ta cần xài hàm SWITCH() của VBA. & điều này bạn có thể tìm hiểu thêm trên diễn đàn lúc rỗi)

D8: Đem trang tính chứa trong biến chuỗi 'ShName' gán vô biến đối tượng kiểu 'Range';
D9: Lấy cột dữ liệu tương ứng (với trị trong 'Cot') đem gán vô biến 'Rng' đã khai báo;
D10: Thực hiện fương thức tìm kiếm giá trị chứa trong TextBox có tên là 'tb_TPL'
(Cần nói thêm rằng có lẽ tên này do bạn ấn định; Chứ tác giả không làm vậy bao giờ)

D11: Đ/K nếu tìm thấy thì thực hiện các lệnh trước D17
D12: Lấy địa chỉ của ô tìm thấy gán vô biến đã khai báo;
D13: Tạo vòng lặp thực hiện chuỗi các lệnh cho đến D16;
D14: Tính giá trị của biến 'SL' tùy thuộc vô trị trong 'Cot' (mà sẽ cộng vô hay trừ đi do chuyện nhập hay xuất tương ứng)

Cần nói thêm rằng tham biến 'SL' được khai báo toàn cục; nên kết quả này sẽ được macro đã gọi nó hay macro khác xài 1 cách vô tư lự.

D15: Thức hiện việc tìm tiếp;
D16: Đ/K để kết thúc việc tìm kiếm là khi ta tìm fải giá trị trong ô thỏa ở tại ô địa chỉ mà ta đã lưu giữ ngay từ ban đầu
D17 & D18: Xem lại D11

Mong rằng đã giúp đỡ bạn được ít nhiều!
--=0
 
Lần chỉnh sửa cuối:
Mong Thầy giải thích cặn kẽ chổ
SL = SL + IIf(Cot = 3, -1, 1) * sRng.Offset(, 2).Value
c
ác số 3,-1,1 và Offset(,2)
Cám Ơn Thầy.
 
Muốn hiểu tường tận nó, ta nên lưu tâm đến macro cha/mẹ của nó; Nó đây:
PHP:
Private Sub CmdTon_Click()
 TinhTNX 1
 TinhTNX 2
 TinhTNX 3
 Me!tb_SLT.Value = SL:                  SL = 0
End Sub

Có nghĩa là macro cha gọi con đến 3 lần lần lượt; & mỗi lần như vậy đều cung cấp cho 'Con' 1 tham biến tăng dần (từ 1)

Trường hợp gọi đầu tiên là ta xử lí với trang tính 'Ton';
Trường hợp cuối là xử anh 'Xuat'
Như vậy khi xuất thì ta fải trừ đi (số có trong kho)
Hai trường hợp đầu thì mang dấu '+' do nhập vô (kho)

Như vậy diễn dịch cụ thể câu lệnh đó sẽ là vầy:

Tham biến 'SL' sẽ được tăng hay giảm với số liệu có trong ô cách ô bên fải ô tìm thấy 1 ô;
Tăng khi tham biến truyền bằng với 2 trường hợp đầu
Giảm với trường hợp gọi lần cuối.

Chúc vui!
;;;;;;;;;;;
 
Hàm IIf em diễn giải như vầy có đúng không Thầy:
SL = SL + IIf(COt = 3,-1,1)
1/nếu SL là "Xuat" (Cot = 3) thì trừ (-1)
2/ Cón lại là cộng (1)
có đúng không Thầy.
 
Bạn diễn dịch như vậy là loại dịch "thoáng"

Dịch chắc fải là vậy:

Nếu đang ở trang 'Xuat' thì số liệu được đem nhân với -1 & cộng vô tham biến
Bằng không fải trang này thì cộng vô tham biến sau khi đã nhân với 1 (cho dù nó là số âm hay dương)

Chúc vui!
 
Web KT
Back
Top Bottom