2016-09-27 5 views
-1

したがって、最初の列の情報がある程度一致するかどうかに応じて行を結合する大きなデータセットがあります。私はこれを行うことができるマクロがあるのだろうかと思っていた。以下では、同様の単純化されたデータセットの画像を取り上げました。私はマクロが新しいワークシートに新しいテーブルを作成するか、既存のデータの下に行を挿入すると思いますが、わかりません。この問題に関するヒントやヒントは非常に役に立ちます。Excel VBAセルが最初の文字と一致する場合は行を挿入します

サンプルデータセット:

Sample Dataset

出力:

Output

+0

を。特に良い質問をする方法と同様の質問をチェックする方法については、特に。条件が満たされたときに行を挿入することについては、ここで何百ものマクロがあります。 – teylyn

+0

um私は推測する –

答えて

0

次の(コメント)コード試みる可能性があります質問を投稿する前にいくつかの研究を行ってください

Option Explicit 

Sub main() 
    Dim cell As Range, cell2 As Range 

    With Worksheets("experiment").Range("A1").CurrentRegion '<--| reference data worksheet(change "experiment" to its actual name) cell "A1" contiguous range column "A" 
     .Sort key1:=Range("A1"), order1:=xlAscending, Header:=xlYes '<--| sort it by "experiment" column to have "smaller" names at the top 
     For Each cell In .Offset(1).Resize(.Rows.Count - 1, 1) '<--| loop through its 1st column cells skipping header row 
      If cell.Value <> "" Then '<--| if current cell isn't blank (also as a result of subsequent operations) 
       .AutoFilter Field:=1, Criteria1:="*" & cell.Value & "*" '<--| filter on referenced column to get cell "containing" current cell content 
       If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 2 Then '<--| if more than 2 rows has been foun: header row gets always filtered so to have at least 2 rows to consolidate we must filter at least 3 
        With .Offset(1).Resize(.Rows.Count - 1) '<--| reference filtered rows skipping header row 
         For Each cell2 In .Offset(, 1).Resize(, .Columns.Count - 1).SpecialCells(xlCellTypeVisible).Areas(1).Rows(1).Cells '<--| loop through 1st filtered row cells skipping 1st column ("experiment") 
          cell2.Value = WorksheetFunction.Subtotal(9, cell2.EntireColumn) '<--| update their content to the sum of filtered cells in corresponding column 
         Next cell2 
         With .Resize(, 1).SpecialCells(xlCellTypeVisible) '<--| reference filtered rows 1st column ("experiment") cells 
          .Value = .Cells(1, 1) '<--| have them share the same name 
         End With 
         .RemoveDuplicates Columns:=Array(1), Header:=xlNo '<--| remove duplicates, thus leaving the 1st filtered row with totals 
        End With 
       End If 
      End If 
     Next cell 
     .Parent.AutoFilterMode = False '<--| show all rows back 
    End With 
End Sub 
+0

「このサイトは無料のコード作成サービスではありません」または「問題のあるコードを投稿する」に何が起こったのでしょうか?あなたは彼らのためにやっているので、あなたは何の仕事もしないように人々を誘っています。 – teylyn

+0

それは働いた!ありがとうございますuser3598756!どこから始めるべきか、助けや指示が必要なことさえ知らなかったので、私はコードを投稿しませんでした。誰かが完全なコードを書いてくれることは決してありません。代わりに、誰かがヒントを書いたり、コードを書いたりするのを期待していましたが、本当にありがとうございました! –

+0

あなたは大歓迎です。次に、回答を受け入れたものとしてマークすることができます。 – user3598756

0

最初の列の最初の数文字を抽出し、カラムを追加します。次に、新しい列を行に、ピリオドの他の列をピボット・テーブルに作成します。 VBAは必要ありません。

+0

最初の数文字ではなく、 ""で区切られた行にテキストを使用することができます。 –

関連する問題