Excel-vba Columns()。替换为两列

时间:2017-03-01 17:45:17

标签: excel vba excel-vba

以下代码将逗号更改为D列的句号。 我想要D& G.

Option Explicit
    Sub ReplaceDoTwComma()   
            Worksheets("Sheet1").Columns("D").replace _
                What:=",", replacement:=".", LookAt:=xlPart    
    End Sub

我试过了

Worksheets("Sheet1").Columns("D").replace _
Worksheets("Sheet1").Columns("G").replace _

Columns("D", "G")Columns ("D" & "G")但没有运气。

我的好参考是Excel VBA code for replacing all "." by "," in a column

任何指导都将受到高度赞赏。 谢谢!

1 个答案:

答案 0 :(得分:2)

进行两次单独的调用,请记住_表示一行继续,因此需要重复两行:

Option Explicit
Sub ReplaceDoTwComma()   
        Worksheets("Sheet1").Columns("D").replace _
            What:=",", replacement:=".", LookAt:=xlPart    
        Worksheets("Sheet1").Columns("G").replace _
            What:=",", replacement:=".", LookAt:=xlPart 
End Sub

或者

Option Explicit
Sub ReplaceDoTwComma()   
        Worksheets("Sheet1").Range("D:D,G:G").replace _
            What:=",", replacement:=".", LookAt:=xlPart    

End Sub