1
私は以下のシートとコードを用意しています。 F:私が欲しいのは4列でソートする
- まず列F、
- その後、列B、
- 次に列D、
- と最後の列E
列Aのデータをソートすることですしたがって、私はデータセット全体に対して上記のソート(F、B、D、E)を行う必要があります。
また、1行目に上記のデータがいくつかあるため、「全体」列は使用できませんが、特定の「データフィールド」を並べ替える必要があります。
上記のランキングが適用されるように、4番目の並べ替えを追加する方法をお勧めします。
ありがとうございます!
Private Sub Remove_Dubs_IndBB()
Dim i As Long
Dim data As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
data = Range("A2", Range("A" & Rows.Count).End(xlUp)).Count
Call Sum_IF
SendKeys ("{ESC}")
With Range("A2", Range("F" & Rows.Count).End(xlUp))
.Sort Key1:=Cells(1, 6), Order1:=xlDescending, _
Header:=xlNo
For i = 1 To data
If (VBA.Date - Cells(i, 4))/365 > 5 Then
Range(Cells(i, 1), Cells(i, 6)).ClearContents
End If
If (Cells(i, 5) - VBA.Date)/365 < 1.25 Then
Range(Cells(i, 1), Cells(i, 6)).ClearContents
End If
Next i
Range("A2", Range("F" & Rows.Count).End(xlUp).Address).Select
Selection.Sort Key1:=Columns(6), Order1:=xlDescending, _
Header:=xlNo
Selection.Sort Key1:=Columns(2), Order1:=xlDescending _
, Key2:=Columns(4), Order2:=xlDescending _
, Key3:=Columns(5), Order3:=xlDescending _
, Header:=xlNo
Range("A2", Range("F" & Rows.Count).End(xlUp)).RemoveDuplicates (3), Header:=xlNo
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub Sum_IF()
Dim i As Long
Dim data As Integer
data = Range("A2", Range("A" & Rows.Count).End(xlUp)).Count
With Range("A2", Range("F" & data))
For i = 1 To data
.Cells(i, 6).FormulaR1C1 = "=SUMIF(R2C3:R[" & data & "]C3, RC[-3], R2C2:R[" & data & "]C2)"
.Cells(i, 6).Copy
.Cells(i, 6).PasteSpecial xlPasteValues
Next i
End With
End Sub
解決策については、オートフィルタを使用することになります。列Fのデータをソートし、F(オートフィルタを使用して他の値を非表示にする)の一意の値をループし、可視のデータを3つの他の列で並べ替えることができます。しかし、やや難しいアプローチです。 – Tragamor
こんにちはMarc_S。自分のコードにオートフィルタを適用する方法はありますか? – Jeweller89