ALT + F11
点击上方导航栏:插入>模块,输入以下代码
Sub CompareCWithG_OutputToGColumn()
Dim ws As Worksheet
Dim cRange As Range, gRange As Range
Dim cCell As Range
Dim gCell As Range
' 设置工作表和范围
Set ws = ThisWorkbook.Sheets(1) ' 修改为您的工作表名称
Set cRange = ws.Range("C1:C9760") ' C 列范围
Set gRange = ws.Range("G1:G1450") ' G 列范围
' 遍历 G 列
For Each gCell In gRange
If Not IsEmpty(gCell.Value) Then
' 遍历 C 列进行比对
For Each cCell In cRange
If Trim(cCell.Value) = Trim(gCell.Value) Then
' 如果匹配,将 A 列对应值输出到 G 列旁边(例如 H 列)
ws.Cells(gCell.Row, "E").Value = ws.Cells(cCell.Row, "A").Value
Exit For ' 匹配后跳出内循环
End If
Next cCell
End If
Next gCell
MsgBox "匹配完成!A 列对应值已输出到 G 列旁边的 H 列。"
End Sub
进入需要筛选的数据表
ALT + F8
选择新添加的模块,点击执行即可