Excel VBA selection.replace,如果已替换,则将文本放在替换行的a列中 [英] Excel VBA selection.replace and if replaced put text in column a of the replaced row

查看:45
本文介绍了Excel VBA selection.replace,如果已替换,则将文本放在替换行的a列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些宏,例如:

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

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

But i want to put the current date (or even just a string of text) to be put in cell A of the row where a replace occurred.

推荐答案

我想您需要将您的替换项更改为查找并替换".像这样:

I imagine you will need to change your replace to a find and replace. Something like:

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 selection.replace,如果已替换,则将文本放在替换行的a列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆