| 
    
     |  | ExcelシートのM列に項目、N列に件数を入力してありN列をキーに降順に並び替えをさせたいのですが、うまくいきません。2行目からデータが入っているのですが、3行目〜最終行までが並び替えされます。(2行目が動かない) 間違いがありましたら、教えて下さい。よろしくお願いします。
 
 Dim i As Integer   '数字カウント
 Dim tel As Integer  '総数
 
 Sub Record2()
 bbb = ActiveWorkbook.Name
 '最終セル
 Range("M1").Select       'A1→M1
 Selection.End(xlDown).Select
 encel1 = ActiveCell.Address
 cend = Mid(encel1, 4)
 
 Cells(10000, 13).End(xlUp).Select
 cend = ActiveCell.Row
 Range("M1").Selec
 '並び替え
 If InStr(1, Cells(cend, 1), "その他", 1) > 0 Then
 cenda = cend - 1
 Else
 cenda = cend
 End If
 
 Range(Cells(2, 13), Cells(cenda, 14)).Select '1→13、2→14
 Selection.SortSpecial SortMethod:=xlSyllabary, Key1:=Range("N1"), _
 Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, _
 MatchCase:=False, Orientation:=xlTopToBottom   'B1→N1
 Range("M1").Select
 '数値合計
 tel = 0
 For i = 2 To cend
 tel = tel + Cells(i, 14)   '2→14
 Next
 Cells(cend + 1, 14) = tel
 'パ−セント
 For i = 2 To cend
 Cells(i, 3).NumberFormat = "0"
 If i = 2 Then
 Cells(i, 15) = Cells(i, 14) / tel * 100 '2→14、3→15
 Else
 Cells(i, 15) = Cells(i, 14) / tel * 100 + Cells(i - 1, 15)
 End If
 Next
 
 End Sub
 
 |  |