|
下準備として、Sheet1,Sheet2のA1:D1セルに、項目を入れておいて下さい。
それ以外は何も入力しないこと。
Sub CSV読み込み2()
Dim MyF As String, Buf As String
Dim Ary As Variant
Dim Num As Integer, i As Integer
Const SvFol As String = _
"C:\Documents and Settings\User\My Documents\My CSV"
'↑保存先フォルダーのパスを正確に指定する。
ChDir SvFol
With Application
MyF = .GetOpenFilename("CSVファイル(*.csv),*.csv")
If MyF = "False" Then Exit Sub
.ScreenUpdating = False
.DisplayAlerts = False
End With
Worksheets(1).Cells.RemoveSubTotal
Worksheets(2).Cells.RemoveSubTotal
Open MyF For Input Access Read As #1
Do Until EOF(1)
Line Input #1, Buf
Ary = Split(Buf, ",")
Num = Val(Ary(0))
If Num < 5 Then
i = 1
ElseIf Num < 7 Then
i = 2
Else
Debug.Print Buf: GoTo NLine
End If
Worksheets(i).Range("A65536").End(xlUp) _
.Offset(1).Resize(, 4).Value = Ary
NLine:
Erase Ary
Loop
Close #1
For i = 1 To 2
With Worksheets(i)
.Range("A1", .Range("A65536").End(xlUp)).Resize(, 4) _
.Sort Key1:=.Range("A1"), Order1:=xlAscending, _
Header:=xlYes, Orientation:=xlSortColumns
.Range("A1").Subtotal 1, xlSum, Array(3), True
.Cells.ClearOutLine
End With
Next i
With Application
ChDir .DefaultFilePath
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
|
|