用点(。)replace逗号(,)只在string中的特定位置

我有多个行,看起来像这样每个string

S087A1097,99,86,0,14,0,good S087A1097,100,0,10,14,0,good S087A1097,0,0,100,0,0,good 

我需要分别改变它。

 S087A1097,99.86,0.14,0,good S087A1097,100.0,10.14,0,good S087A1097,0.0,100.0,0,good 

我怎样才能在Excel中实现这一点

如果您的文本在单元格A1:

 =SUBSTITUTE(SUBSTITUTE(A1,",",".",2),",",".",3) 

如果你想使用VBA解决scheme,你可以尝试下面的代码。

这看起来有点长,但执行速度非常快,因为工作表几乎没有“混乱”,大部分逻辑都在数组上完成。

 Option Explicit Sub ImportCsvContents() Dim csvLines As Variant, CurrentRow As Variant Dim LastRow As Long, i As Long ReDim csvLines(0) With Worksheets(1) LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row ' === logic, each order ends with data data in column "B" === For i = 1 To LastRow csvLines(UBound(csvLines)) = .Range("A" & i).Value ReDim Preserve csvLines(UBound(csvLines) + 1) ' keep record and raise array index by 1 Next i End With ' resize array to actual populated size If csvLines(UBound(csvLines)) = "" Then ReDim Preserve csvLines((UBound(csvLines) - 1)) End If ' loop through all lines in .csv file For i = 0 To UBound(csvLines) CurrentRow = Split(csvLines(i), ",") CurrentRow(1) = CurrentRow(1) & "." & CurrentRow(2) CurrentRow(2) = CurrentRow(3) & "." & CurrentRow(4) CurrentRow(3) = CurrentRow(5) CurrentRow(4) = CurrentRow(6) ' re-format the current line csvLines(i) = CurrentRow(0) & "," & CurrentRow(1) & "," & CurrentRow(2) & "," & CurrentRow(3) & "," & CurrentRow(4) Erase CurrentRow ' clear array Next i ' now just dump the entre array to the worksheet Worksheets(1).Range("A1").Resize(UBound(csvLines) + 1).Value = Application.Transpose(csvLines) End Sub