使用macros更改单元格值

我正在尝试使用Excelmacros更改单元格值。

例如,更改这个组:

Codes: CareBears Catpaws CareBears Catpaws CareBears Doghound Catpaws Doghound 

成:

 Codes: Bear Cat Bear Cat Bear Dog Cat Dog 

我使用macroslogging自动成功地转换了它们,但是当数据切换位置或有另外一行数据时,这些数据没有被读取。

我正在寻求这方面的协助。

在这里输入图像说明

如果你不需要replace这些值,并且只有每一个都必须处理熊,猫和狗,你可以在B列中添加一个公式,如果你的代码在A列。它不漂亮,但它的工作原理。

把它放在B2中,然后抄下来,在A列中input你的代码。

= IF(NOT(ISERROR(SEARCH( “熊”,A2,1))), “熊”,IF(NOT(ISERROR(SEARCH( “狗”,A2,1))), “狗”,IF(NOT (ISERROR(SEARCH( “猫”,A2,1))), “猫”, “?”)))

我很欣赏这不能回答“macros观”的问题。 如果你有像DogBear这样的值,不要尝试和使用它;-)

 Sub FindAndExecute() 'got the answer working with this help http://stackoverflow.com/questions/19504858/find-all-matches-in-workbook-using-excel-vba Dim Sh As Worksheet Dim Loc As Range Dim Loc1 As Range Dim Loc2 As Range For Each Sh In ThisWorkbook.Worksheets With Sh.UsedRange Set Loc = .Cells.Find(What:="Carebears") If Not Loc Is Nothing Then Do Until Loc Is Nothing Loc.Value = "Bear" Set Loc = .FindNext(Loc) Loop End If Set Loc1 = .Cells.Find(What:="Catpaws") If Not Loc1 Is Nothing Then Do Until Loc1 Is Nothing Loc1.Value = "Cat" Set Loc1 = .FindNext(Loc1) Loop End If Set Loc2 = .Cells.Find(What:="Doghound") If Not Loc2 Is Nothing Then Do Until Loc2 Is Nothing Loc2.Value = "Dog" Set Loc2 = .FindNext(Loc2) Loop End If End With Set Loc = Nothing Set Loc1 = Nothing Set Loc2 = Nothing Next End Sub