2017-10-25 10 views
0

に、私はこのはドットでカンマ(、)を交換してください(。)のみ、特定の場所で文字列

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 

テキストがセルA1にある場合にどのように私はエクセル

+0

あなたはVBAベースのソリューションを使用する場合は、あなたは非常に高速 –

答えて

2

でこれを達成することができます

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

の下に私の答えとコードを読み取ることができる、素敵な:) –

+0

ありがとう!私は自分のロケールを変換しなければなりませんでした。これは、この部分で最も混乱していた部分です...すべてがちょうどカンマ、ドット、引用符です:) あなたはとても印象的です! –

+0

ありがとうございます。私の時間は長くなりますが、ワークシートに数式を保存したくない場合は、高速な解決策です –

0

あなたはVBAソリューションを使用する場合は、以下のコードを試すことができます。

これは少し長いように見えるかもしれませんが、ワークシートに「つぶれ」がほとんどなく、実行が非常に高速で、ほとんどのロジックは配列で行われます。

コード

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 
関連する問題