2011-02-17 33 views
4

我有这样一些宏:Excel的VBA selection.replace和列如果换成把文本替换行

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

但是我希望把当前的日期(或者甚至只是文本字符串)放置在发生替换的行的单元格A中。

回答

4

我想你会需要改变你的替换为查找和替换。例如:

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 
+0

+1在2003版本中增加了`SearchFormat`和`ReplaceFormat`,我想,但我认为可以安全地删除早期版本的Excel中的两个参数。 – Fionnuala 2011-02-17 09:44:21