excel表格用VBA按照条件进行筛选,

2024-12-12 20:15:17
推荐回答(3个)
回答1:

Sub 筛选()
Columns("F:I") = ""
Dim I%
For I = 2 To Range("A65536").End(xlUp).Row
If Cells(2, 2) = "运输中" And InStr(Cells(I, 3), "裸素鱼竿") > 0 Then
n = n + 1
Cells(n + 1, "F") = Cells(I, 1)
Cells(n + 1, "G") = Cells(I, 2)
Cells(n + 1, "H") = Cells(I, 3)
Cells(n + 1, "I") = Cells(I, 4)
End If
Next
End Sub
B列 订单状态名称为 运输中, 且 C列产品名称数据包含了 裸素鱼竿
都能筛选出来
结果从F列显示

回答2:

试试下面这段代码,根据需要修改
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 3 Then
If Target.Value = Range("e2") Then Range("e" & Cells(Rows.Count, "e").End(3).Row).Offset(1).Value = Target.Offset(0, -2).Value
If Target.Value = Range("f2") Then Range("f" & Cells(Rows.Count, "f").End(3).Row).Offset(1).Value = Target.Offset(0, -2).Value
End If
End Sub

回答3:

我会写,文件呢。有文件才好测试