替换工作表中的单元格值

时间:2015-10-30 09:24:33

标签: excel vba excel-vba excel-formula

我需要一个宏,它取“I2”中的值,然后用空格键“”替换它在Sheet中的任何地方然后转到“I3”并执行相同的操作直到〜“I6000”并且如果可能的话直到“Z6000” “重要:如果可能的话,它应该只删除确切的值,所以如果有一个”5“它应该只删除它,其中”5“是一个单独的字符串而不是”5675“并使其成为”67“

编辑:我在1个单元格示例中有超过1个值:“ValueC ValueZ Value5 95 C-69”

我有这段代码:

Range("I2").Select
Application.CutCopyMode = False
Selection.Copy
Cells.Replace What:=I2, Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

End Sub  

如何更改它以通过“L2” - “Z6000”?

示例屏幕截图excel with highlight

Example Screenshot excel with highlight

1 个答案:

答案 0 :(得分:1)

用户关注代码将完成您的工作。

 Sub fillValue()

cellValue = Range("I2").Value

For i = 1 To 6000    'increase this value to add more rows
compareValue = Range("A" & i).Value
if compareValue = cellValue then
Range("A" & i).Value = ""
end if

compareValue = Range("B" & i).Value
if compareValue = cellValue then
Range("B" & i).Value = ""
end if


'Add as many column as you want.


Next
End Sub

在excel中,您无法将单个键指定给宏。您必须使用Ctrl键的组合进行分配,如下图所示。

enter image description here

相关问题