2016-04-28 13 views
-3

をマージし、統合:Microsoft Excelの - 私は、Excelでの3つのカラム持っている問題

A1:Car  | B1:Ford | C1:Toyota 
A2:Scooter | B2:Honda | C2:(blank) 
A3:Bike | B3:Yamaha | C3:Ducati 

私に結果を与える:私は、私は以下のような行を持っている場合は、そのようなリストを統合する

Column A: Category 
Column B: Value 
Column C: Value 

を:

A1:Car  | B1:Ford 
A2:Car  | B2:Toyota 
A3:Scooter | B3:Honda 
A4:Bike | B4:Yamaha 
A5:Bike | B5:Ducati 

Image explaining the issue

+0

マクロが提案したマクロ!多くの皆さんありがとうございます – Adi

答えて

0

次のコードは、これがすべてアクティビティシートで起こっていると主張します。

Sub consolidate() 

Dim lastRow As Integer 
Dim lastCol As Integer 
Dim counterRow As Integer 
Dim counterCol As Integer 
Dim counterDestinationRow As Integer 
Dim destination As Object 

lastRow = Cells(Rows.Count, 1).End(xlUp).Row 

Set destination = Cells(lastRow + 2, 1) 
'or to another sheet: Set destination = Sheets("Sheet2").Cells(1, 1) 

For counterRow = 1 To lastRow 

    lastCol = Cells(counterRow, Columns.Count).End(xlToLeft).Column 

    For counterCol = 2 To lastCol 

     destination.Offset(counterDestinationRow, 0) = Cells(counterRow, 1) 
     destination.Offset(counterDestinationRow, 1) = Cells(counterRow, counterCol) 

     counterDestinationRow = counterDestinationRow + 1 

    Next counterCol 

Next counterRow 

End Sub 
+0

こんにちはマルコ。それは部分的に働いた。実際のスプレッドシートを共有できるメールアドレスはありますか? – Adi

+0

確かに、使用[email protected] –

+0

ありがとうMarco。ちょうど送られた。とても感謝しています – Adi

0

プログラミングはされていません。

ステップ0:AS新しいシートを保存:)

  1. 列C(テキストとしてコピー)
  2. にカラムから
  3. コピー値カテゴリ(これは、新しい列Cである)Cの前に列を挿入
  4. は、列C及びD内のすべての値を選択し、最後の値Aの直下にペーストをコピーしB.
  5. 列cおよびカラムA、次にBに
  6. ソートDを削除し、空の値列
  7. で、空行を削除します
+0

ありがとうございました。 ありがとうございます。 問題は1回限りではないということです。 月々のレポートです。 索引vlookupの式を使用する入力ファイルから 'Car'カテゴリに対して 'Ford'や 'Toyota'のような値を取得しました。 出力ファイルをピボットとグラフにフィードできるように、式を使用して出力を必要な形式(別のシート内)に持っていく必要があります – Adi

+0

ソースから何か得られますか?データはどこから来たのですか? –

+0

こんにちはJan.ありがとう。ソースは定期的なレポートから来ており、かなりの数の列を含んでいます。私は既存の行列を検索し、入力列の連結に対応する値を見つける必要があります。問題は検索結果が複数であるため、インデックス式(fordやトヨタなど)を使ってそれらを呼び出す。 – Adi

関連する問題