excel多個工作表數據快速合並到一個工作表方法


1、假設分別有工作表1、2、3。

 

2、將鼠標指針移至“Sheet1”,右鍵選擇“查看源代碼”,即可打開VBE編輯器,

 

 3、在工程窗口下的Microsoft Excel對象右鍵“插入”,點擊“模塊”,新建一個模塊1。

 

 

4、輸入所示的代碼。

Option Explicit

Sub hbgzb()

Dim sh As Worksheet, flag As Boolean, i As Integer, hrow As Integer, hrowc As Integer

flag = False

For i = 1 To Sheets.Count
 
If Sheets(i).Name = "合並數據" Then flag = True

Next

If flag = False Then

Set sh = Worksheets.Add

sh.Name = "合並數據"

Sheets("合並數據").Move after:=Sheets(Sheets.Count)

End If

For i = 1 To Sheets.Count

If Sheets(i).Name <> "合並數據" Then

hrow = Sheets("合並數據").UsedRange.Row

hrowc = Sheets("合並數據").UsedRange.Rows.Count

If hrowc = 1 Then

Sheets(i).UsedRange.Copy Sheets("合並數據").Cells(hrow, 1).End(xlUp)

Else

Sheets(i).UsedRange.Copy Sheets("合並數據").Cells(hrow + hrowc - 1, 1). Offset(1, 0)

End If

End If

Next i

End Sub

 

 

 

5、按ALT+F8打開宏對話框窗口,單擊執行hbgzb宏。

 

 

6、即可實現excel多個工作表數據快速合並到一個工作表。

 

 

 

轉發自:http://xinzhi.wenda.so.com/a/1520747020206402

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM