-4
私は、書式設定を標準化するために数式で実行したレポートデータを6枚持っています。これらのシートでは、私が必要とするデータは、列AL:BW
にあり、長さが異なり、ヘッダーが一致しています。複数のシートのデータを統合するExcel
ここでは、すべてのデータを集計シートにまとめて、グラフ/レポートをより簡単に作成する必要があります。私はVBAが解決できるとはかなり確信していますが、私は各シートの同じ列範囲を選択し、そのデータを要約シートにコンパイルすることができる回答をオンラインで見つけられませんでした。
私はこのarticleから解決策を試してきましたが、具体的にはAL:BW
列のデータをターゲットにするためのVBAについては十分に分かりません。
Sub CopyData()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim shLast As Long
Dim CopyRng As Range
Dim StartRow As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
' Delete the summary sheet if it exists.
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("CombinedData").Delete
On Error GoTo 0
Application.DisplayAlerts = True
' Add a new summary worksheet.
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "CombinedData"
' Fill in the start row.
StartRow = 2
' Loop through all worksheets and copy the data to the
' summary worksheet.
For Each sh In ActiveWorkbook.Worksheets
If LCase(Left(sh.Name, 4)) = "?-??" Then
' If source worksheet is not empty and if the last
' row >= StartRow, copy the range.
If shLast > 0 And shLast >= StartRow Then
'Set the range that you want to copy
Set CopyRng = sh.Range("AL:BL")
' Test to see whether there are enough rows in the summary
' worksheet to copy all the data.
If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
MsgBox "There are not enough rows in the " & _
"summary worksheet to place the data."
GoTo ExitTheSub
End If
' This statement copies values and formats.
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
End Sub
私は助けてくれてありがとう!
ありがとうございました。何らかの理由で、マクロは実際にデータを統合していません。私はいくつか微調整を行いましたが、問題を正確に特定できませんでした。 – JLantz
最後の行と最後の列を取得する関数を含めるのを忘れてしまった。私はちょうどそれらを加えた。もう一度やり直してフィードバックをください。 – ryguy72
それは動作します!ワークブックにマクロから除外したいシートがいくつかあります。フォーマットされているワークシートのみをターゲットにする方法はありますか?どこ? "は変数ですか? – JLantz