excel使用vba进行数据筛选

2025-01-08 06:00:25
推荐回答(2个)
回答1:

Sub tiqu()
Dim i, j, k As Integer
k = 1
i = 100
For j = 2 To i
If Sheets("Sheet1").cells(j, 2).Text = "2班" and Sheets("Sheet1").cells(j, 3).value= 2002 Then
Sheets("sheet1").cells(j, 1).Copy Sheets("sheets2").cells(k,1)
k = k + 1
End If
Next j
End Sub
在SHEET1中:
开发工具-插入-表单控件-按钮
按钮-右键-指定宏-新建-复制本段代码

回答2:

Private Sub CommandButton1_Click()
For r = 2 To Sheet1.[a65535].End(xlUp).Row
If Cells(r, "B") = "2班" And Cells(r, "C") = "2002" Then
N = N + 1
Sheet2.Cells(N, "A") = Sheet1.Cells(r, "A")
Sheet2.Cells(N, "B") = Sheet1.Cells(r, "B")
Sheet2.Cells(N, "C") = Sheet1.Cells(r, "C")
End If
Next
End Sub