简体   繁体   English

比较sheet1和sheet2中的单元格值,然后在sheet3中输出具有相同值的整行单元格

[英]Compare cells value in sheet1 and sheet2 then output entire row of the cells with same value in sheet3

Can you help me about my concern?你能帮我解决我的顾虑吗? I have 3 sheets , sheet1 ,sheet2 and sheet3 .我有 3 张, sheet1 ,sheet2 和 sheet3 。 I want to compare the excel value or text which is in sheet1 and sheet2.我想比较sheet1和sheet2中的excel值或文本。 Sheet1 contains value from column A until C. But the only value need to compare to sheet 2 column A is the value in column A which is in sheet1. Sheet1 包含从 A 列到 C 列的值。但唯一需要与工作表 2 列 A 进行比较的值是在工作表 1 中的 A 列中的值。 Once the both column (A in sheet1 and A in sheet2) was compared the same value The output will be displayed in sheet3 .一旦两列(sheet1 中的 A 和 sheet2 中的 A)比较相同的值,输出将显示在 sheet3 中。 Same value of two column (A sheet1 and sheet2) will be displayed included those in column B and C .将显示两列(A sheet1 和 sheet2)的相同值,包括列 B 和 C 中的值。 my code is working but cannot include value in column B and C of the same value.我的代码正在运行,但不能在 B 列和 C 列中包含相同值的值。 Thanks for any help you can give me.感谢你给与我的帮助。

sheet1 :表1:

columnA | columnB |    columnC

C2S3    |   L9     |    number 229 available

C2S14   |   LBS    |    number 221229 available

C2S17   |   LQP    |    number 222726 available


C3S90   |   LQSH2  |    number 222729182 available

C3S91   |   LQSH2  |    number 222729190 available

C3S9    |   PLR    |    number 262228 available

C3S10   |   RFFH   |    number 28161618 available

C3S11   |   BWT1s  |    number 123330129 available

sheet2 :表2:

columnA |

C2S3

C2S14

C2S17

C3S1

C3S5

C3S9

C3S10

C3S11

C3S12

C3S14

C3S15

sheet3 output: sheet3 输出:

C2S3    |   L9    |    number 229 available

C2S14   |   LBS   |    number 221229 available

C2S17   |   LQP   |    number 222726 available



C3S9    |   PLR   |    number 262228 available

C3S10   |   RFFH  |    number 28161618 available

C3S11   |   BWT1s |    number 123330129 available

here's my code:这是我的代码:

Private Sub CommandButton1_Click()

Dim oldRow As Integer

Dim newRow As Integer

Dim i As Integer

i = 1 

For oldRow = 1 To 300

    For newRow = 1 To 300

        If StrComp((Worksheets("Sheet1").Cells(oldRow, 1).Text),
        (Worksheets("Sheet2").Cells(newRow, 1).Text), vbTextCompare) <> 0 
        Then

             i = oldRow

             Worksheets("Sheet3").Cells(i, 3) = "" 'clear the cells

        Else

            Worksheets("Sheet3").Rows(newRow).Value = 
            Worksheets("Sheet2").Rows(newRow).Value 

            i = i + 1

            Exit For

        End If

    Next newRow

Next oldRow

MsgBox "Done Compare", vbOKOnly

End Sub

Try this and see if it works.试试这个,看看它是否有效。 I had trouble following some of the logic in your code.我无法遵循您代码中的某些逻辑。 I think that my suggestion should set columns A, B, and C of oldRow in Sheet3 to the values of oldRow in Sheet1.我认为我的建议应该将 Sheet3 中 oldRow 的 A、B 和 C 列设置为 Sheet1 中 oldRow 的值。

Where you have these lines of code.你在哪里有这些代码行。

        Worksheets("Sheet3").Rows(newRow).Value = 
        Worksheets("Sheet2").Rows(newRow).Value 

Try this and see if it works for you.试试这个,看看它是否适合你。

    Worksheets("Sheet3").Cells(oldRow, 1).Value = Worksheets("Sheet1").Cells(oldRow, 1).Value
    Worksheets("Sheet3").Cells(oldRow, 1).Offset(0, 1).Value = Worksheets("Sheet1").Cells(oldRow, 1).Offset(0, 1).Value
    Worksheets("Sheet3").Cells(oldRow, 1).Offset(0, 2).Value = Worksheets("Sheet1").Cells(oldRow, 1).Offset(0, 2).Value

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 比较sheet1和sheet2中的单元格值,然后将整行移动到sheet3 - Compare cells value in sheet1 and sheet2 then move entire row to sheet3 根据 sheet1(table1) 中同一行中的值复制特定单元格并粘贴到 sheet2(table2) 下一个可用行 - Copy specific cells based on value in the same row in sheet1(table1) and paste into sheet2(table2) next available row 将 sheet1 中的每一行与 sheet2 中的每一行进行比较 - 在​​ sheet3 中没有对写入 - 难 - Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD 如果((Sheet2,Column A)或(Sheet3,Column A))中的值不存在于(Sheet 1,Column A)中,则在 Sheet1 中创建新行 - Create New Row in Sheet1 if Value in ((Sheet2, Column A) or (Sheet3, Column A)) Doesn't Exist in (Sheet 1, Column A) 根据当前工作表(例如Sheet1)中的值,禁用另一工作表(例如Sheet2)上单元格的范围 - disable the range of cells on another sheet ( say Sheet2) based on the value in the current sheet(say Sheet1) 将Sheet1第2行中的黄色单元格依次复制到Sheet2 - Copy Yellow Cells in Row 2 of Sheet1 sequentially to Sheet2 将工作表1中的所有单元格从A + AC复制到工作表3,然后在工作表1中删除行 - Copy All cells from A + AC in sheet1 to Sheet3 then delete row in Sheet1 搜索范围Sheet1对Sheet2中的范围根据横向单元格中的值复制到Sheet3 - Searching Range Sheet1 Against Range in Sheet2 Copy to Sheet3 depending on value in lateral cell 将行值从 sheet1 复制到 sheet2 列 - Copy row value from sheet1 to sheet2 column 如何在 Sheet3 中合并 Sheet1 和 Sheet2? - How to consolidate Sheet1 and Sheet2 in Sheet3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM