|
Sub chaxun()
Dim ar As Variant
Dim br()
Dim rn As Range
With Sheets("系统数据")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:j" & r)
End With
With Sheets("入库")
zd = .[c1]
rs = .Cells(Rows.Count, 2).End(xlUp).Row
If zd <> "" Then
ReDim br(1 To UBound(ar), 1 To 6)
For i = 2 To UBound(ar)
If InStr(ar(i, 7), zd) > 0 Then
n = n + 1
For j = 2 To 4
br(n, j - 1) = ar(i, j)
Next j
br(n, 4) = ar(i, 7)
br(n, 5) = ar(i, 8)
br(n, 6) = n
End If
Next i
If n = "" Then MsgBox "没有符合条件的数据!": End
For i = 5 To rs
If Trim(.Cells(i, 2)) = "" Then
If rn Is Nothing Then
Set rn = .Rows(i)
Else
Set rn = Union(rn, .Rows(i))
End If
End If
Next i
If Not rn Is Nothing Then rn.Delete
.Rows("5:" & n + 4).Insert Shift:=xlDown
.Cells(5, 3).Resize(n, UBound(br, 2)) = br
.Cells(5, 3).Resize(n, UBound(br, 2)).Borders.LineStyle = 1
.Cells(5, 3).Resize(n, UBound(br, 2)).Interior.ColorIndex = 10
Else
For i = 5 To rs
If Trim(.Cells(i, 2)) = "" Then
If rn Is Nothing Then
Set rn = .Rows(i)
Else
Set rn = Union(rn, .Rows(i))
End If
End If
Next i
If Not rn Is Nothing Then rn.Delete
End If
End With
End Sub
|
|