EXCEL 将符合条件的列复制到指定的位置

2025-03-31 02:45:41
推荐回答(2个)
回答(1):

用以下代码,只要在A1单元格输入字节,即把符合条件的数据自动填入B列:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i, j As Long
Dim l As Integer
Application.EnableEvents = False
Range("B:B").ClearContents
If Target.Address <> "$A$1" Or IsEmpty(Target.Value) Then
Application.EnableEvents = True
Exit Sub
End If
i = Range("A65536").End(xlUp).Row
l = Len(Target.Value)
j = 2
For Each rg In Range("A2:A" & i)
If UCase(Left(rg.Value, l)) = UCase(Target.Value) Then
Cells(j, 2) = rg.Value
j = j + 1
End If
Next
Application.EnableEvents = True
End Sub

回答(2):

筛选