返回列表 上一主題 發帖

合併多個工作表內資料於新增1工作表

  1. Sub nn()
  2.   Dim iI%, iRowEnd%, iTarRow%
  3.   Dim sGroup$
  4.   Dim vMer
  5.   
  6.   Set vMer = Sheets("合併")
  7.   iTarRow = 2
  8.   
  9.   For iI = 1 To Sheets.Count
  10.     With Sheets(iI)
  11.       If .Name <> vMer.Name Then
  12.         sGroup = .Name
  13.         iRowEnd = .Cells(Rows.Count, 1).End(xlUp).Row
  14.         .Range(.Cells(2, 1), .Cells(iRowEnd, 2)).Copy
  15.         With vMer
  16.           .Paste Destination:=.Cells(iTarRow, 1)
  17.           .Cells(iRowEnd + iTarRow - 2, 3) = sGroup
  18.           .Range(.Cells(iTarRow, 3), .Cells(iRowEnd + iTarRow - 2, 3)).FillUp
  19.         End With
  20.         iTarRow = iRowEnd + iTarRow - 1
  21.       End If
  22.     End With
  23.   Next iI
  24. End Sub
複製代碼

TOP

        靜思自在 : 做好事不能少我一人,做壞事不能多我一人。
返回列表 上一主題