我有一个包含三个工作表的工作簿。我需要根据工作簿A上的列A和C以及工作表上的列B和D的条件(索引?),使用工作簿A中的列CF(行)的值更改工作簿B上的列K(行)中的值B.也就是说,这些工作表具有不同顺序的数据,不能简单地循环并复制。我需要在工作表A中找到CF(行)的行号,其中工作表A和C列与工作表A B和D列相同。
PsuedoSQL
UPDATE
Worksheet B
SET
Worksheet B.K = Worksheet A.CF
FROM
Worksheet A
WHERE
Worksheet A.B = Worksheet B.B
从工作表A中选择,CF列WHERE A.A和A.C等于工作表B.B和B.D AND SET工作表B.K(行)到值工作表A.CF(行)
我的代码是一个查找,它在工作表A列A上找到带有匹配文本的LAST列,没有任何索引或映射。
Public Function FindPnum(keyword As Variant) As Variant
Dim ws As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim tRow As Long
Dim tCol As Integer
Set ws = Sheets("Data")
Set rng1 = ws.Cells.Find(keyword, ws.[b2], xlValues, , xlByRows, xlPrevious)
Set rng2 = ws.Cells.Find(keyword, ws.[b2], xlValues, , xlByColumns, xlPrevious)
If Not rng1 Is Nothing Then
FindPnum = Cells(rng1.Row, rng2.Column).Address(0, 0)
End If
End Function
答案 0 :(得分:1)
这里试试这个
Sub pair()
Dim r, r2, found
r = 8
r2 = 2
found = False
Application.ScreenUpdating = False
Sheets(2).Activate
Do Until Len(Cells(r, 2).Value) = 0
Do Until Len(Sheets(1).Cells(r2 + 1, 2).Value) = 0 Or found = True
If Sheets(2).Cells(r, 2).Text = Sheets(1).Cells(r2, 2).Text Then
If Sheets(2).Cells(r, 11).Value <> 0 Then
Sheets(2).Cells(r, 11).Value = Sheets(1).Cells(r2, 84)
End If
found = True
Else
r2 = r2 + 1
End If
Loop
r2 = 2
r = r + 1
found = False
Loop
Application.ScreenUpdating = True
End Sub
我认为应该这样做。