|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim ras, rae, rgs, rge As Integer
- Dim i, j, k As Integer
- ras = Cells(1, 1).End(xlDown).Row 'A列第一个数据所在的行
- rae = Cells(Rows.Count, 1).End(xlUp).Row 'A列最后一个数据所在的行
- rgs = Cells(1, 7).End(xlDown).Row 'G列第一个数据所在的行
- rge = Cells(Rows.Count, 7).End(xlUp).Row 'G列最后一个数据所在的行
- k = 0
- For i = ras To rae
- For j = rgs To rge
- If Cells(i, 1) = Cells(j, 7) Then
- Cells(i, 3).Value = Cells(i, 1).Value
- Exit For
- End If
- Next j
- Next i
- For i = rgs To rge
- For j = ras To rae
- If Cells(i, 7) = Cells(j, 1) Then Exit For
- If (Cells(i, 7) <> Cells(j, 1)) And (j = rae) Then
- k = k + 1
- Cells(rae + k, 3).Value = Cells(i, 7).Value
- End If
- Next j
- Next i
- End Sub
复制代码 |
|