我编写了这段代码,将我的所有工作表合并到sheet(1)
,并插入了几列来区分不同工作表的数据。
代码如下:
Sub Combine()
Dim i As Integer
Dim xTCount As Variant
Dim xWs As Worksheet
On Error Resume Next
Set xWs = ActiveWorkbook.Worksheets.Add(Sheets(1))
xWs.Name = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 16)
Worksheets("Presanitization").Range("A1").EntireRow.Copy Destination:=xWs.Range("A1")
Worksheets(1).Range("A1").EntireColumn.Insert
Worksheets(1).Range("A1").EntireColumn.Insert
Worksheets(1).Range("A1").EntireColumn.Insert
Range("A1") = "Identifier"
Range("B1") = "Batch ID"
Range("C1") = "Phase"
For i = 4 To Worksheets.Count
Worksheets(i).Range("D1").CurrentRegion.Offset(CInt(1), 0).Copy _
Destination:=xWs.Cells(xWs.UsedRange.Cells(xWs.UsedRange.Count).Row + 1, 4)
Next
Worksheets(1).Columns("A:l").ColumnWidth = 16
Worksheets(1).Columns("A:z").HorizontalAlignment = xlCenter
Worksheets(1).Range("B2") = xWs.Name
Worksheets(1).Range("A2") = Left(xWs.Name, Len(xWs.Name) - 3)
End Sub
现在,我想将工作表名称复制到工作表的column "C"
中并将其复制到该工作表的数据末尾。
如何对所有数据重复此操作?
有人可以帮我修改我的代码吗?