Dim dongdau As Long, sodong As Long, dongcuoi As Long, iSoCT As Long, endR As Long
Dim Dem As Long, iL As Long
Dim Data As Range, SoCT As Range, rngFound As Range
Sub CapNhat()
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Sheet1.Select
sodong = [E30].End(xlUp).Row - 12 'Lay dong cuoi cot sl'
iSoCT = Sheet1.[G6].Value
If sodong < 1 Then
MsgBox "ban chua nhap"
'Else
'Set Data = Range("B13:H" & songdong + 13)'
End If
'Phai them dong so cot cho dep va de dang hon'
With Sheet3
dongdau = .[D65000].End(xlUp).Row
If dongdau = 5 Then dongdau = 6
dongcuoi = dongdau + sodong
'***Gan so lieu cho cac cot tai sh Xuat'
.Range("A" & dongdau + 1 & ":A" & dongcuoi).Value = Sheet1.[F36].Value 'Ngay'
.Range("B" & dongdau + 1 & ":B" & dongcuoi).Value = Sheet1.[G6].Value 'so chung tu'
.Range("C" & dongdau + 1 & ":C" & dongcuoi).Value = Sheet1.[F36].Value 'ngay chung tu'
.Range("D" & dongdau + 1 & ":D" & dongcuoi).Value = Sheet1.[C8].Value 'Ten KH'
.Range("E" & dongdau + 1 & ":E" & dongcuoi).Value = Sheet1.[B9].Value 'Dia chi KH'
.Range("F" & dongdau + 1 & ":F" & dongcuoi).Value = Sheet1.Range("H13:H" & 13 + sodong).Value 'MaSP'
.Range("G" & dongdau + 1 & ":G" & dongcuoi).Value = Sheet1.Range("B13:B" & 13 + sodong).Value 'dien giai'
.Range("I" & dongdau + 1 & ":I" & dongcuoi).Value = Sheet1.Range("D13:D" & 13 + sodong).Value 'dvt'
.Range("J" & dongdau + 1 & ":J" & dongcuoi).Value = Sheet1.Range("E13:E" & 13 + sodong).Value 'Sl'
.Range("K" & dongdau + 1 & ":K" & dongcuoi).Value = Sheet1.Range("F13:F" & 13 + sodong).Value 'DG'
.Range("L" & dongdau + 1 & ":L" & dongcuoi).Value = Sheet1.Range("G13:G" & 13 + sodong).Value 'TT'
End With
'***Xoa Sale'
[G6,C8,B9].ClearContents
[B13:B30].ClearContents
[E13:F30].ClearContents
iSoCT = iSoCT + 1
[G6] = iSoCT
[C8].Select
MsgBox "OK"
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
Sub TimCT()
With Application
.EnableEvents = False: .DisplayAlerts = False
.ScreenUpdating = False: .Calculation = xlCalculationManual
End With
Sheet1.Select
endR = Sheets("Xuat").Range("D65000").End(xlUp).Row
iSoCT = Application.InputBox("Tu so:", "Thu Nghi", Type:=1)
Set SoCT = Sheet3.Range("B5:B" & endR)
Dem = WorksheetFunction.CountIf(SoCT, iSoCT)
If Dem = 0 Then
MsgBox "Khong co so ct"
Exit Sub
Else
Set rngFound = SoCT(1)
Set rngFound = SoCT.Find(iSoCT, After:=rngFound, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
With rngFound
[G6] = iSoCT
[C8] = .Offset(, 2).Value 'Ten KH'
[B9] = .Offset(, 3).Value 'Dia chi'
[F36] = .Offset(, -1).Value 'ngay'
Range("B13:B" & 13 + Dem - 1).Value = .Offset(, 5).Resize(Dem, 1).Value 'tenhang'
Range("E13:E" & 13 + Dem - 1).Value = .Offset(, 8).Resize(Dem, 1).Value 'so luong'
Range("F13:F" & 13 + Dem - 1).Value = .Offset(, 9).Resize(Dem, 1).Value 'Don gia'
End With
End If
'MsgBox "OK"'
With Application
.DisplayAlerts = True: .ScreenUpdating = True
.EnableEvents = True: .Calculation = xlCalculationAutomatic
End With
End Sub