Excel copy data from multiple worksheets

*爱你&永不变心* 提交于 2019-12-12 03:58:33

问题


Is there a way to copy cell ranges from multiple worksheets into another worksheet? For example:
Sheet1
Apple
Grapes
Peach
Cherry
Sheet2
Orange
Pear
Banana
Blueberry

I need the result as

Sheet3
Apple
Grapes
Peach
Cherry
Orange
Pear
Banana
Blueberry

Assume I have the data in Column A in the Sheet 1 & 2 and I need to display the combined results in Column A on Sheet3. Basically I need to display all items from Sheet 1 & 2 in Sheet3 in one column.

Any ideas? Thanks in advance.


回答1:


Since your data is in the same columns, I am assuming all you really need to do is copy paste each sheet into one master sheet. This VBA function I found a while back on the web (so sorry to the original creator, I wish I knew who it was so I can credit him). It will combine all worksheets into one worksheet called "Master". Saves a lot of time! I hope this helps or gets you close to where you need to be.

Sub CreateMasterSheet()

Application.ScreenUpdating = False
Dim wrk As Workbook
Dim sheet As Worksheet
Dim masterSheet As Worksheet
Dim rng As range

Set wrk = ActiveWorkbook

For Each sheet In wrk.Worksheets
    If sheet.Name = "Master" Then
        MsgBox "There is a worksheet called as 'Master'." & vbCrLf & _
                "Remove or rename this worksheet.", vbOKOnly + vbExclamation, "Error"
        Exit Sub
    End If
Next sheet

Set masterSheet = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.count))
masterSheet.Name = "Master"

For Each sheet In wrk.Worksheets
    If sheet.Index = wrk.Worksheets.count Then
        Exit For
    End If
    Set rng = sheet.range(sheet.cells(1, 1), sheet.cells(65536, 1).End(xlUp).Resize(, 256))
        masterSheet.cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.count, rng.Columns.count).Value = rng.Value
Next sheet

masterSheet.Columns.AutoFit
Application.ScreenUpdating = True
End Sub



回答2:


You did not mention your version of Excel. In 2003 and 2010, you can do this using Data, Consolidate. See your version's help for the procedure.



来源:https://stackoverflow.com/questions/6823009/excel-copy-data-from-multiple-worksheets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!