帮忙解决一个EXCEL问题:在表格1中添加表格2中的一列中的部分数据.
帮忙解决一个EXCEL问题:在表格1中添加表格2中的一列中的部分数据.
具体问表格1中第一列为学号,排列不规则,不能改变其顺序,需要添加数据的地方为第4列;需要从表格2中的第三列中提取,其中表格2的第一列也是学号,但是和表格1相比,是顺序也打乱的,而且有更多的学号.
也就是说,不能通过简单的经过排列学号来解决,我还有一个类似的宏,但是不会用,请各位大侠指导.
'搜索,标注
Sub tll()
Dim n As Integer
Dim k
For n = 2 To 500
Workbooks("2.xls").Activate
k = Workbooks("2.xls").Sheets(1).Cells(n,4).Value
Workbooks("1.xls").Activate
If Workbooks("1.xls").Worksheets(1).Cells.Find(k) Is Nothing Then
Else:Workbooks("1.xls").Worksheets(1).Cells.Find(k).Font.ColorIndex = 3
Workbooks("2.xls").Sheets(1).Cells(n,4).Font.ColorIndex = 3
End If
Next
End Sub
'搜索,拷贝相关内容
Sub tll()
Dim n As Integer
Dim k
Dim s
For n = 3 To 15
Workbooks("2.xls").Activate
k = Workbooks("2.xls").Sheets(1).Cells(n,3).Value
Workbooks("1.xls").Activate
If Workbooks("1.xls").Worksheets(1).Cells.Find(k) Is Nothing Then
Else:Workbooks("1.xls").Worksheets(1).Cells.Find(k).Font.ColorIndex = 3
Workbooks("1.xls").Worksheets(1).Cells.Find(k).Select
Application.Selection.Offset(0,9).Copy
Workbooks("2.xls").Sheets(1).Cells(n,7).PasteSpecial
Workbooks("2.xls").Sheets(1).Cells(n,3).Font.ColorIndex = 3
End If
Next
End Sub
'对比两列
Sub tll()
Dim n As Integer
Dim k
Dim s
For n = 2 To 1000
Workbooks("2.xls").Activate
k = Workbooks("2.xls").Sheets(1).Cells(n,2).Value
s = Workbooks("2.xls").Sheets(1).Cells(n,3).Value
If k s Then
Else:Workbooks("2.xls").Sheets(1).Cells(n,2).Font.ColorIndex = 3
Workbooks("2.xls").Sheets(1).Cells(n,3).Font.ColorIndex = 3
End If
Next
End Sub