![](/img/trans.png)
[英]How to compare two columns in Excel (from different sheets) and copy values from a corresponding column if the first two columns match?
[英]How to compare two columns in Excel (from different sheets) and replace values in the corresponding column?
我有两个尺寸相同的Excel工作表。 我需要将工作表1中的a列与工作表2中的a列进行比较,以便可以在工作表1中找到任何值为“ 1”的行,然后需要在工作表2中找到相应的行并将其替换为NAN。
任何帮助将不胜感激。
谢谢
Sub compareRange()
Dim ran1, ran2 As Range
Dim index As Integer
Set ran1 = Sheet1.Range("a1:a50")
Set ran2 = Sheet2.Range("a1:a50")
index = 0
For Each c In ran1.Cells
index = index + 1
If (c.Value = 1) Then
ran2.Cells(index).Value = "NAN"
End If
Next
End Sub
函数Vlookup可以解决您的问题。 Excel的帮助指南对功能进行了清晰的说明。
我不确定是否可以覆盖其他单元格中的某个单元格,但是可以这样做:
=IF(Sheet1!A1=1, "NAN", Sheet2!A1)
在Sheet3中,将以上内容复制到MxN
单元中(sheet1和sheet2的尺寸)。 这将在相同的sheet1包含1的单元格中提供具有NAN的Sheet2的相同副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.