Excel VBA 选择.替换,如果替换,则将文本放在替换行的 a 列中

标签 excel vba

我有一些宏,例如:

Columns("F:M").Select
Selection.Replace What:=",", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False

但我想将当前日期(甚至只是一个文本字符串)放入发生替换的行的单元格 A 中。

最佳答案

我想您需要将替换更改为查找和替换。像这样的东西:

Dim c As Range
Columns("F:M").Select
Set c = Selection.Find(What:=",", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False)
If Not c Is Nothing Then
    Do
        c.Replace What:=",", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
            ReplaceFormat:=False
        Cells(c.Row, 1).Value = Date
        Set c = Selection.FindNext(c)
    Loop While Not c Is Nothing
End If

关于Excel VBA 选择.替换,如果替换,则将文本放在替换行的 a 列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5026423/

相关文章:

excel - 将超链接添加到仅受用户界面保护的工作表

vba - 在 excel vba 中选择纸张尺寸(非默认尺寸)

java - Java中的贝塞尔库函数

excel - 定义一系列单元格。像 Shift + 单击

excel - 我该如何处理: “No item of this name exists in the PivotTable report.” 错误

excel - 复制带有选中复选框的行

html - 从网页获取数据

excel - 在 Excel 中使用 vba 插入公式时出现“@”

excel - 基于动态 Sum_Range 的 SUMIFS

asp.net - 在指向 ASP.Net Web 应用程序的 Excel 超链接中使用查询字符串