【问题标题】:Get value of one column based on value of two OTHER columns, then change column on another worksheet根据两列其他列的值获取一列的值,然后在另一个工作表上更改列
【发布时间】:2012-08-31 21:03:17
【问题描述】:

我有一个包含三个工作表的工作簿。我需要根据工作簿 A 上的列 A 和 C 以及工作表上的列 B 和 D 的条件(索引?),将工作簿 B 上的列 K(行)中的值更改为工作簿 A 中的列 CF(行)的值B. 也就是说,这些工作表具有不同顺序的数据,不能简单地循环和复制。我需要在工作表 A 中找到 CF(row) 的行号,其中工作表 A 和 C 列与工作表 A B 和 D 列相同。

伪SQL

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 AND A.C 等于工作表 B.B 和 B.D 并将工作表 B.K(Row) 设置为 Value worksheetA.CF(row)

我的代码是查找工作表 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

【问题讨论】:

    标签: excel excel-2007 vba


    【解决方案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
    

    我认为应该这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      相关资源
      最近更新 更多