-1

マクロを使用してVBAでこれを作成する方法が完全にはわかりません。

私は単一のワークブック、Compare.xlsを持っています。その中の2枚のシート、Sheet1とSheet2。

基本的に私は取ろうとしています:

Sheet1

Date    ID  Other   Sub     Chan
10000   100 Repeat  X       30  
10000   101 Repeat  X       40

Sheet2

ttc   event     Chan
XYZ   L         30
XYZ   L         40
XYZ   L         6

そして、このデータから、Sheet1のChan列をSheet2の一致するレコードChanレコードと比較し、結合されたデータを両方のシートから新しいシートに出力する必要があります。

出力例は次のようになります。

Date    ID  Other   Sub     Chan   ttc
10000   100 Repeat  X       30     xyz

前進する方法に関するスニペットに関する提案はありますか?

4

2 に答える 2

1

リクエストは簡単なVLOOKUP関数で処理できます。

ステップ1:Sheet2で、列C(別名列 "Chan")をコピーしてワークシートの先頭に配置します。これで、Sheet2データは次のようになります。

Chan    ttc    event
30      XYZ    L
40      XYZ    L
6       XYZ    L

ステップ2:Sheet1で、Sheet1の最後に列(列Fである必要があります)を追加し、「ttc」という名前を付けます(これは、Sheet2から検索するものであるため)。これで、Sheet1データは次のようになります。

Date    ID  Other   Sub     Chan    ttc
10000   100 Repeat  X       30   
10000   101 Repeat  X       40 

ステップ3:Sheet1の列Fに次の関数を入力します

=VLOOKUP(E2,Sheet2!$A$2:$C$4,2,)

この数式を入力すると、結果がすぐに表示されます

Explanation:  the Excel Vlookup function takes the following four arguments, which are
                  separated with a comma:
    1st argument is the cell (E2) containing the value in Sheet 1 to look for
    2nd argument contains the range of data to look into (which resides in Sheet2 and the
                 cell range A2 through C4 is where the data resides.
                 NOTE1:  the VLOOKUP function requires the 1st column of Sheet2 to be the column
                         to look into
                 NOTE2:  we don't need to include the 1st row containing the header
                 NOTE3:  the dollar signs represent absolute cell range so that when you copy it
                         down to other rows below them, they don't change (i.e., your data range
                         in Sheet2 is always the same
    3rd argument represents the column # in Sheet2 to return if there's a match.
                 NOTE:  column 1 starts with column A of Sheet2
    4th argument is left blank

ステップ4:この数式を以下の列Fの他のすべての行にコピーします注:後続の行には数式が含まれている必要があります

=VLOOKUP(F2,Sheet2!$A$2:$C$4,2,)
=VLOOKUP(G2,Sheet2!$A$2:$C$4,2,)  if you have 3 rows in Sheet1
=VLOOKUP(H2,Sheet2!$A$2:$C$4,2,)  if you have 4 rows in Sheet1

等...

于 2012-07-29T04:05:51.247 に答える
0

VBAを使用したいことに気づきました-組み込みの数式でこれを簡単に実行できるのはなぜかわかりませんか?

を使用して逆行しているので、を使用しVLLOKUPてみてください...INDEXMATCH

これが簡略化されたバージョンです...

ここに画像の説明を入力してください

于 2012-07-12T07:03:16.473 に答える