Excel VBA selection.replace,如果被替换,则将文本放在被替换行的a列中
我有一些宏,比如:Excel VBA selection.replace,如果被替换,则将文本放在被替换行的a列中,excel,vba,Excel,Vba,我有一些宏,比如: Columns("F:M").Select Selection.Replace What:=",", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _ ReplaceFormat:=False 但是我想把当前日期(甚至只是一个文本字符串)放在发生替换的行的单元格a中。我想您需要将替换更改为查找并替换。比如: Dim
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
+我认为,1
SearchFormat
和ReplaceFormat
是在2003年版本中添加的,但我认为对于早期版本的Excel,这两个参数可以安全地删除。@Remou,我实际上在Excel2000上测试了它们,并且只添加了它们,因为它们存在于问题中。所以是的,它起作用了^_^