简体   繁体   English

如何比较不同工作表中两列的不存在的值,然后将它们复制到主工作表中?

[英]How do I compare two columns in different sheets for non existing values and then copy them to the main sheet?

Firstly, I am no expert with VBA, just searching for similar situation copying them, changing the code a bit and hoping for the best. 首先,我不是VBA的专家,只是寻找类似的情况来复制它们,略微更改代码并希望获得最佳效果。

So I need to make a macro that compares two sheets. 所以我需要做一个比较两张纸的宏。 One of the sheets is the one that contains history information and all the specific names in Column A, where in the other sheet I paste daily information, where the specific names is always in column C and starts with row 7. The existing names could disappear or new names could be added and there will be duplicates. 一张纸是在A列中包含历史信息和所有特定名称的一张纸,在另一张纸中,我粘贴了每日信息,其中特定的名称始终在C列中并从第7行开始。现有名称可能会消失或可以添加新名称,并且会有重复的名称。

What I need is for the code to first compare these two Columns for new names, if such are found copy them and past them in the history sheets A columns 2nd row, the existing names get moved down, so that they don't get deleted. 我需要的代码是先比较这两列的新名称,如果找到新名称,将其复制并粘贴到历史记录表的第二列A列的第二行中,现有名称将向下移动,以使它们不会被删除。

In short words saying If duplicate do nothing, else copy to history sheet. 简而言之,如果重复则什么也不做,否则复制到历史记录表。

Thank you in advance for all the help 预先感谢您的所有帮助

Not sure of what your logic would be, but here are some VBA Pointers: 不确定您的逻辑将是什么,但是这里有一些VBA指针:

To compare columns in different sheets: 要比较不同工作表中的列:

If Sheets("Sheet1").Range("ColRow").Value <> Sheets("Sheet2").Range("Col2Row2").Value Then... 如果Sheets(“ Sheet1”)。Range(“ ColRow”)。Value <> Sheets(“ Sheet2”)。Range(“ Col2Row2”)。Value然后...

Or you could replace the sheet names with (1) and (2) [or whatever order they are in the workbook]. 或者,您可以用(1)和(2)[或它们在工作簿中的任何顺序]替换工作表名称。

For instance: If Sheets(1).Range("A2").Value <> Sheets(2).Range("C7").Value Then ... 例如:如果Sheets(1).Range(“ A2”)。Value <> Sheets(2).Range(“ C7”)。Value然后...

Assignment to a cell works similarly. 分配给单元的工作原理类似。 You can use a variable as an index: 您可以将变量用作索引:

Dim i1 as integer
Dim i2 as integer
i2 = 7
For i1 = 1 to 50
    If Sheets(1).Range("A" + CStr(i1)).Value <> Sheets(2).Range("C" + CStr(i2)).Value Then
        Sheets(1).Range("B" + Cstr(i1)).Value = Sheets(2).Range("C" + CStr(i2)).Value
    End If

    i2 = i2 + 1
Next i1

暂无
暂无

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

相关问题 如何将两张不同的纸上的列复制到一张纸 - How to copy columns from two different sheets into one sheet 如何比较两个不同的 excel 工作表中的列,如果找到匹配项,则复制其他列值 - How to compare columns in two different excel sheets and if match found copy other other column values 如何比较Excel中的两列(来自不同工作表),如果前两列匹配,则复制相应列中的值? - How to compare two columns in Excel (from different sheets) and copy values from a corresponding column if the first two columns match? VBA:一种快速方法,用于比较两个不同工作表中的两列,并从工作表1中相应单元格旁边的第二个工作表中复制值 - VBA : Fast method to compare two columns in two different sheets and copy value from 2nd sheet next to the respective cell in sheet 1 如何在两张工作表中获取不匹配的列成员并将其复制到Excel中的新工作表中? - How to get unmatched columns members in two sheets and copy them to a new sheet in excel? 如何比较包含字符串值的两张表中的两列并在另一张表中打印更新? - how to compare two columns in two sheets which contain string values and print the update in another sheet? 如何从两个不同的工作表中搜索数据并将它们复制到第三张工作表? - How to search data from two different sheets and copy them to a third sheet? 如何比较不同工作表中的两列 - How to compare two columns in different sheets 比较两张表并检查不同的值/数据并更新主表 - Compare two sheets and check for different values/data and update master sheet 如何比较不同工作表中的两列,然后将值放入另一工作表中? vba - How to compare two columns from different sheets and put a value in another sheet? vba
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM