NguyenAnnn
Thành viên mới
- Tham gia
- 8/11/22
- Bài viết
- 4
- Được thích
- 0
Sub Button2_Click()
Dim ShNhap As Worksheet, ShXuat As Worksheet, ShTheKho As Worksheet
Dim arr(), kq(), i As Long, a As Long, lr As Long
Dim TuNgay As Date, DenNgay As Date, TenSP As String
Set ShNhap = Sheets("NHAPKHO")
Set ShXuat = Sheets("XUATKHO")
Set ShTheKho = Sheets("TheKho")
TuNgay = ShTK.Range("I1").Value
DenNgay = ShTK.Range("I2").Value
TenSP = ShTheKho.Range("B4").Value
With ShNhap
lr = .Range("A" & Rows.Count).End(xlUp).Row
arr = .Range("A5:I" & lr).Value
ReDim kq(1 To 10000, 1 To 5)
End With
For i = 1 To UBound(arr, 1)
If arr(i, 2) >= TuNgay And arr(i, 2) <= DenNgay And arr(i, 5) = TenSP Then
a = a + 1
kq(a, 1) = arr(i, 2) 'Ngay
kq(a, 2) = arr(i, 1) 'So chung tu
kq(a, 3) = arr(i, 3) 'ncc
kq(a, 4) = arr(i, 8) 'sl nhap
'kq(a, 5) = "" 'spxuat
End If
Next i
With ShXuat
lr = .Range("A" & Rows.Count).End(xlUp).Row
arr = .Range("A5:I" & lr).Value
For i = 1 To UBound(arr, 1)
If arr(i, 2) >= TuNgay And arr(i, 2) <= DenNgay And arr(i, 5) = TenSP Then
a = a + 1
kq(a, 1) = arr(i, 2) 'Ngay
kq(a, 2) = arr(i, 1) 'So chung tu
kq(a, 3) = arr(i, 3) 'ncc
' kq(a, 4) = arr(i, 8) 'sl nhap
kq(a, 5) = arr(i, 2) ' slxuat
End If
Next i
End With
' dan ra sheets
If a > 10000 Then
MsgBox "Ket qua vuot qua 10000 dong, vui long chon thoi gian ngan hon!", vbCritical
Exit Sub
End If
With ShTheKho
If a > 0 Then
.Range("A11:E10010").ClearContents ' xoa trang truoc khi dan
.Range("A11").Resize(a, 5).Value = kq
End If
End With
End Sub
Dim ShNhap As Worksheet, ShXuat As Worksheet, ShTheKho As Worksheet
Dim arr(), kq(), i As Long, a As Long, lr As Long
Dim TuNgay As Date, DenNgay As Date, TenSP As String
Set ShNhap = Sheets("NHAPKHO")
Set ShXuat = Sheets("XUATKHO")
Set ShTheKho = Sheets("TheKho")
TuNgay = ShTK.Range("I1").Value
DenNgay = ShTK.Range("I2").Value
TenSP = ShTheKho.Range("B4").Value
With ShNhap
lr = .Range("A" & Rows.Count).End(xlUp).Row
arr = .Range("A5:I" & lr).Value
ReDim kq(1 To 10000, 1 To 5)
End With
For i = 1 To UBound(arr, 1)
If arr(i, 2) >= TuNgay And arr(i, 2) <= DenNgay And arr(i, 5) = TenSP Then
a = a + 1
kq(a, 1) = arr(i, 2) 'Ngay
kq(a, 2) = arr(i, 1) 'So chung tu
kq(a, 3) = arr(i, 3) 'ncc
kq(a, 4) = arr(i, 8) 'sl nhap
'kq(a, 5) = "" 'spxuat
End If
Next i
With ShXuat
lr = .Range("A" & Rows.Count).End(xlUp).Row
arr = .Range("A5:I" & lr).Value
For i = 1 To UBound(arr, 1)
If arr(i, 2) >= TuNgay And arr(i, 2) <= DenNgay And arr(i, 5) = TenSP Then
a = a + 1
kq(a, 1) = arr(i, 2) 'Ngay
kq(a, 2) = arr(i, 1) 'So chung tu
kq(a, 3) = arr(i, 3) 'ncc
' kq(a, 4) = arr(i, 8) 'sl nhap
kq(a, 5) = arr(i, 2) ' slxuat
End If
Next i
End With
' dan ra sheets
If a > 10000 Then
MsgBox "Ket qua vuot qua 10000 dong, vui long chon thoi gian ngan hon!", vbCritical
Exit Sub
End If
With ShTheKho
If a > 0 Then
.Range("A11:E10010").ClearContents ' xoa trang truoc khi dan
.Range("A11").Resize(a, 5).Value = kq
End If
End With
End Sub