本帖最后由 shelluserwlb 于 2015-1-8 20:34 编辑
你这个数据很多的话完全可以放在excel中用VBA实现的
将“测试1”放到 sheet1 中分成两列(A列和B列),将"测试2"放到 sheet2 (A列)中,再运行下面的代码,结果就会出现在"sheet3"中了。- Sub a()
- Dim n1, n2 As Integer
- Dim index1, index2 As String
- Dim vlue1, vlue2 As String
- n1 = WorksheetFunction.CountA(Worksheets("sheet1").Columns(1))
- n2 = WorksheetFunction.CountA(Worksheets("sheet2").Columns(1))
- index1 = 1
- Do While index1 <= n1
- vlue1 = Worksheets("sheet1").Cells(index1, 1)
- index2 = 1
- Do While index2 <= n2
- vlue2 = Worksheets("sheet2").Cells(index2, 1)
- If vlue1 = vlue2 Then
- Worksheets("Sheet1").Cells(index1, 1).Copy _
- Destination:=Worksheets("Sheet3").Cells(index1, 1)
- Worksheets("Sheet1").Cells(index1, 2).Copy _
- Destination:=Worksheets("Sheet3").Cells(index1, 2)
- Exit Do
- End If
- index2 = index2 + 1
- Loop
- index1 = index1 + 1
- Loop
- MsgBox "操作成功!"
- End Sub
复制代码
|