[英]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.