VBA Excel查找并replace没有replace已经replace的项目

我正在寻找一个可以find和replace数据的excel脚本,但是对于所有我无法想象如何写的数据的爱。

情况:

甲———– ———–乙Ç

猫——- ——狗香蕉

狗鱼—— ——苹果

鱼——猫——-橙

因此,macros将查看B列单元格中的数据,然后查看列C中的相邻单元格,并将A列中的所有数据的实例replace为C中的数据。因此,结果将为:

甲————— ———–乙Ç

橙色——狗——香蕉

香蕉鱼—— ——苹果

苹果——– ——-猫橙色

但是,这并不是全部,我希望它不会改变已经被更改过一次的单元格! (我试图改变背景颜色)

任何帮助? 我完全失去了。

编辑:

好吧,我发现如何做简单的部分(replace),但我不知道如何改变已经改变了一次的单元格。 这是我的代码:

Sub multiFindNReplace() Dim myList, myRange Set myList = Sheets("sheet1").Range("A2:B3") 'two column range where find/replace pairs are Set myRange = Sheets("sheet1").Range("D2:D5") 'range to be searched For Each cel In myList.Columns(1).Cells myRange.Replace what:=cel.Value, replacement:=cel.Offset(0, 1).Value, ReplaceFormat:=True Next cel End Sub 

据我所知,ReplaceFormat:= True不会做任何事情; /所以已经被replace一次的项目仍然被replace! 有没有办法以某种方式使这项工作?

以下是使用您的颜色作为一次性限制的build议的答案:

 Sub Replace_Once() 'Find last row using last cell in Column B LastRow = Range("B" & Rows.Count).End(xlUp).Row 'Clear colors in Column A Range("A1:A" & LastRow).Interior.ColorIndex = xlNone 'Look at each cell in Column B one at a time (Cel is a variable) For Each Cel In Range("B1:B" & LastRow) 'Compare the cell in Column B with the Value in Column A one at a time (C is a variable) For Each C In Range("A1:A" & LastRow) 'Check if the Cell in Column A matches the Cell in Column B and sees if the color has changed. If C.Value = Cel.Value And C.Interior.Color <> RGB(200, 200, 200) Then 'Colors the cell C.Interior.Color = RGB(200, 200, 200) 'Updates the value in Column A with the cell to the right of the Cell in Column B C.Value = Cel.Offset(0, 1).Value End If Next Next 'Uncomment the line below to remove color again 'Range("A1:A" & LastRow).Interior.ColorIndex = xlNone End Sub