vba - 用 Excel VBA 中的函数替换单元格区域

标签 vba excel string-substitution

我必须在 Excel 文件中将一个字符替换为另一个字符。

我使用了以下Replace函数,但由于某些单元格超出了1024个字符的限制,它就停在那里。

Sub Replace()

    With Sheets("Sheet1").Range("A1:A629")   

      .Cells.Replace ",", ";", xlPart, xlByRows, False

    End With

End Sub 

我知道Substitute函数可以做到

Cells(1, 2) = "=SUBSTITUTE(A1,"","","";"")"

但是我如何将其用于单元格范围?

最佳答案

试试这个

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

enter image description here

关于vba - 用 Excel VBA 中的函数替换单元格区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17561274/

相关文章:

excel - 合并多个 Worksheet_SelectionChange

vba - Visual Basic Excel 消息框

raku - 在 for 循环中用 .subst 替换字符串

vba - 如何在 Excel 中找到任何宏或 VBA?

excel - 根据单元格值隐藏图表

excel - 从 VBA 中的类模块中提取特定变量到标准模块

excel - 使用 Excel VBA : wait for the page to fully load 使用 XML HTTP 请求抓取网站

sql - 如何在 Access 中进行分层\级联查询\报告?

python - 数学表达式中类型字符串替换的字符串操作

c++ - 用于使用 ostream 左移语法替换 printf 样式调用的正则表达式