![見出し画像](https://assets.st-note.com/production/uploads/images/138151462/rectangle_large_type_2_ff803c92a8da5d542b2d2ccd97692966.png?width=1200)
memo csv読込み時に文字列置換
Sub テキスト読み込み()
Dim txtName As String
'取り込むテキストファイルを選択
txtName = Application.GetOpenFilename("テキストファイル,*.csv")
If txtName <> "False" Then
Open txtName For Input As #1
End If
Dim r As Long
r = 1 '1行目から書き出す
Do Until EOF(1) '改行まで繰り返す
Dim buf As String
Line Input #1 , buf
Dim aryLine As Variant '文字列格納用配列変数
buf = Replace(buf, ",-,", ",無,")
aryLine = Split(buf, ",") '読み込んだ行をカンマ区切りで配列変数に格納
Dim i As Long
For i = LBound(aryLine) To UBound(aryLine)
'インデックスが0から始まるので列番号に合わせるため+1
Cells(r, i + 1) = aryLine(i)
Cells(r, i + 1).NumberFormatLocal = "@"
Cells(r, i + 1).NumberFormatLocal = "0"
Next
r = r + 1
Loop
Close #1
MsgBox "終了しました。"
End Sub
この記事が気に入ったらサポートをしてみませんか?