用Excel VBA替代单元格范围的功能 [英] Substitute Function in Excel VBA for cell range
本文介绍了用Excel VBA替代单元格范围的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在Excel文件中用一个字符替换另一个字符.
I have to replace one character with another in Excel file.
我已经使用了以下Replace
函数,但是由于某些单元格中超过1024个字符的限制,因此该操作会停止在该位置.
I have used following Replace
function, but due to exceeds of 1024 character limit in some cells, it stops there.
Sub Replace()
With Sheets("Sheet1").Range("A1:A629")
.Cells.Replace ",", ";", xlPart, xlByRows, False
End With
End Sub
我知道Substitute
函数会做
Cells(1, 2) = "=SUBSTITUTE(A1,"","","";"")"
但是如何将其用于单元格范围?
But how do I use that for cell range?
推荐答案
尝试一下
Sub Replace()
Dim rng As Range, cell As Range
Set rng = Sheets("Sheet1").Range("A1:A629")
For Each cell In rng
cell = WorksheetFunction.Substitute(cell, ",", ";")
Next
End Sub
这篇关于用Excel VBA替代单元格范围的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文