excel - 对源单元格本身应用 REPLACE 函数
问题描述
是否可以在 Excel 中格式化将公式的结果应用于单元格本身?
我有一个包含文本的单元格。文本以不需要的项目符号开头,我想使用下面的 REPLACE 功能删除前导项目符号。
将单元格 A2 视为包含带有前导特殊字符(项目符号)的文本的源,我想在其上应用此功能并希望将结果文本粘贴回 A2
=replace(A2,1,6,””)
有任何想法吗?
解决方案
假设您在一列(示例代码中的 5)上的单元格包含“x 12345”、“x 3456”、“x abcd”等文本,将转换为:“12345”、“3456”、“abcd”等。您可以设置strRepl
为任何字符串:
Sub testReplace()
Dim sh As Worksheet, colNo As Long, arrCol As Variant
Dim lastRow As Long, i As Long, strRepl
Set sh = ActiveSheet ' put here your sheet
colNo = 5 'Column E:E
strRepl = "x " 'use here your string to be removed
lastRow = sh.Cells(sh.Rows.count, colNo).End(xlUp).Row
arrCol = sh.Range(Cells(1, colNo), Cells(lastRow, colNo)).Value
For i = 1 To UBound(arrCol)
arrCol(i, 1) = Replace(arrCol(i, 1), "x ", "")
Next i
sh.Range(Cells(1, colNo), Cells(lastRow, colNo)) = arrCol
End Sub
推荐阅读
- flutter - 在图像上手动设置 firebaseStorageDownloadTokens 使用 Flutter 上传到 Firebase 存储
- powerbi - Power BI - 日期切片器不适用于合并查询
- css - 升级后 JSX 样式不适用于 Storybook
- winapi - WIN32:有没有办法让按钮图标(BM_SETIMAGE)出现在文字的右侧
- c# - 继承具有不同基类的多个类的通用功能
- css - 扩大 rmarkdown html 中代码的输出
- c++ - 在没有参数列表的情况下无效使用模板名称'boost::asio::strand'
- javascript - 如何将用户生成的 svg 上传到服务器?
- java - 如果 logger.error() 在 try 块中命中/显示,则执行 catch 块
- node.js - Node.js 应用架构设计并行处理