2011-02-17 157 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