
Windows 10 エクセル 2019
製品データと製品リストという 2 つのワークシートを含むワークブックがあります。探している数式が実行されるたびに、製品リストのデータが生成されます。
製品の数は不明/無制限です。
各製品の行数は不明/無制限です。
各ワークシートにはヘッダー行があります。
製品データ ページでは、
列 A、B、J、K には重複した日付があり、各製品に関連する行を識別するために使用されます。
列 G と H も各製品に関連していますが、値が混在しており、製品の識別には使用されません。
各製品 (製品リスト シートの列 A、B、J、K の一致するデータによって識別される) について、Excel で列 G を調べ、一致する各データ セットで最も多く出現する番号を返す必要があります。おそらく、'=MODE.SNGL(G2:G) を一致の最後まで返します。
必要なコード/数式は、次の処理を実行します。
最初の一致した値のセット (黄色) が処理されると、次に次の一致したセット (緑)、さらに次の一致したセット (青) と、製品リスト シートの最後まで処理し、製品リスト ページにコピーします (下の例)。
私は、Products Date ワークシートからデータを取得する次の VBA を持っていますが、列 G 範囲のコードに '=MODE.SNGL(G2:G) またはそれに類似するものを挿入して、一致するデータ セットごとにループして新規に開始する方法がわかりません。
' セル A2 からセル G2、行 40,000 まで、ワークシート「Track Data2」からデータを取得するための式が挿入されます。
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK('Track Data'!RC), """",IF(OR('Track Data'!RC[8]=""Wav"",'Track Data'!RC[8]=""Flac"",'Track Data'!RC[8]=""Mp3"",'Track Data'!RC[8]=""Aif"",'Track Data'!RC[8]=""OSX AU""),'Track Data'!RC,""""))"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""","""",'Track Data'!RC)"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-2]="""","""",'Track Data'!RC[8])"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-3]="""","""",'Track Data'!RC)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-4]="""","""",'Track Data'!RC[2])"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-5]="""","""",'Track Data'!RC[])"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-6]="""","""",'Track Data'!RC[2])"
Range("A2:G2").Select
Selection.AutoFill Destination:=Range("A2:G40000"), Type:=xlFillDefault
Range("A2:G40000").Select
Application.GoTo Reference:="R2C1"
製品データ ワークシートの例。
PRODUCT TYPE DATA 1 DATA 2 DATA 3 DATA 4 NO 1 N0 2 DATA 5 PRICE PACK TYPE
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 4 1058 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 4 652 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 2 331 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 2012 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 300 442 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 43 442 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 300 442 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 21 5678 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 14 442 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 62 789 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 300 442 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 300 1233 Data 5 9.89 Tube
Yellow Paint Oil Data 1 Data 2 Data 3 Data 4 300 442 Data 5 9.89 Tube
Black Paint Powder Data 1 Data 2 Data 3 Data 4 1 3 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 1 45 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 2 20 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 3 3 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 3 8 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 6 3 Data 5 6.28 Tin
Black Paint Powder Data 1 Data 2 Data 3 Data 4 1 3 Data 5 6.28 Tin
製品リストページの外観の例。
PRODUCT TYPE DATA 1 DATA 2 DATA 3 DATA 4 M. DUPS No 2 DATA 5 PRICE PACK TYPE
Red Paint Powder Data 1 Data 2 Data 3 Data 4 12 1058 Data 5 22.99 Tin
Yellow PaintOil Data 1 Data 2 Data 3 Data 4 300 442 Data 5 9.89 Tube
Black Paint Powder Data 1 Data 2 Data 3 Data 4 1 3 Data 5 6.28 Tin