|
集計する列を間違えていたようです。すいません。以下のコードでやってみて下さい。
Sub CSV読み込み2()
Dim MyF As String, Buf As String
Dim Ary As Variant
Dim Num As Integer, i As Integer
Dim C As Range
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)
For Each C In .Range("D2", .Range("D65536").End(xlUp))
C.Value = Val(C.Value)
Next
.Range("A1", .Range("A65536").End(xlUp)).Resize(, 4) _
.Sort Key1:=.Range("A1"), Order1:=xlAscending, _
Header:=xlYes, Orientation:=xlSortColumns
.Range("A1").Subtotal 1, xlSum, Array(4), True
.Cells.ClearOutline
End With
Next i
With Application
ChDir .DefaultFilePath
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
|
|