松井証券で取引している方向けの取引ファイルのEXCELデータ化

クラシックでログイン=>資産状況=>取引履歴でCSVファイルでデータダウンロードした複数のCSVファイルを一つにまとめるEXCELのマクロを以下の通り作成しました。
以下を理解できるかかたはお使いください。



Sub Macro1()


folder = ThisWorkbook.Path: 'csvファイルのあるフォルダーを指定。ここでは今使っているEXCELファイルのフォルダーとしている。


Sheets("sheet1").Select: '書込みシートをセット

Cells.Select
Selection.ClearContents
Selection.NumberFormatLocal = "@"

Columns("A:A").Select
Selection.NumberFormatLocal = "yyyy/m/d"
Columns("F:G").Select
Selection.NumberFormatLocal = "0.0_ "
Columns("H:H").Select
Selection.NumberFormatLocal = "yyyy/m/d"
Columns("I:I").Select
Selection.NumberFormatLocal = "0.0_ "



Range("A1").Select
Dim d(28) As String


Cells(1, 1) = "約定日"
Cells(1, 2) = "銘柄コード"
Cells(1, 3) = "銘柄名"
Cells(1, 4) = "売買"
Cells(1, 5) = "区分"
Cells(1, 6) = "数量"
Cells(1, 7) = "約定単価"
Cells(1, 8) = "建日"
Cells(1, 9) = "建単価"

i = 2
x = Dir(folder + "\*.csv")

Do Until x = ""


Open folder + "\" + x For Input As #1
Line Input #1, x


Do Until EOF(1) = True


For j = 1 To 28
Input #1, d(j)
Next


If Left(d(10), 2) = "返済" Then
Cells(i, 1) = d(2)
Cells(i, 2) = d(3)
Cells(i, 3) = d(4)
Cells(i, 4) = d(8)
Cells(i, 5) = d(10)
Cells(i, 6) = d(11)
Cells(i, 7) = d(12)
Cells(i, 8) = d(17)
Cells(i, 9) = d(18)
i = i + 1
End If



Loop


x = Dir()

Loop


Close


End Sub

×

非ログインユーザーとして返信する