1
我試圖從同一工作簿中的多個其他工作表構建母版工作表。信息被格式化在一個表格中,並且需要在主表格中保持這種狀態。 Master和其他選項卡全部基於模板表單。我可以成功構建母版頁,但表格格式將覆蓋複製標籤中的任何字體顏色。以下是我的代碼。在保存表格的同時,是否有任何想讓字體顏色成功複製到母版頁的想法?從表格中複製表格,保留字體顏色
Sub Combine()
Dim i As Integer
Dim j As Integer
Dim ws1 As Worksheet
'Adding multiple String variables for 5 accounts
Dim account1 As String
Dim account2 As String
Dim account3 As String
Dim account4 As String
Dim account5 As String
'Naming which account worksheets need to be copied into the Master worksheet, only for use with Naming Method below
account1 = "x"
account2 = "xx"
account3 = "xxx"
account4 = "xxxx"
account5 = "xxxxx"
'Deleting any previous Master worksheet
For Each SheetExists In Worksheets
If SheetExists.Name = "Master" Then
Application.DisplayAlerts = False 'Turn off alerts to avoid annoyance
SheetExists.Delete
Application.DisplayAlerts = True 'Turn alerts back on
Exit For
End If
Next SheetExists
'Creating a blank Master worksheet based upon the Template worksheet
Set ws1 = ThisWorkbook.Worksheets("Template")
ws1.Copy ThisWorkbook.Sheets(Sheets.Count)
ActiveSheet.Name = "Master"
ActiveSheet.Move before:=Worksheets(1) 'Moves Master worksheet to first tab
'Naming Method, selecting specific worksheets based upon names, for each additional worksheet name add another Or statement to the If Then line
For Each SheetExists In Worksheets
If SheetExists.Name = account1 Or SheetExists.Name = account2 Or SheetExists.Name = account3 Or SheetExists.Name = account4 Or SheetExists.Name = account5 Then 'Matching worksheet names as needed
SheetExists.Activate 'Make the sheet active
Range("A1").Select
Selection.CurrentRegion.Select 'Select all cells in this sheet
Selection.Offset(2, 0).Resize(Selection.Rows.Count - 3).Select 'Select all rows except top and header
Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2) 'Copy cells selected into the Master sheet on the last line available
Range("A1").Select 'Deselects entire worksheet so everything isn't highlighted
End If
Next SheetExists
'Activates Master worksheet
Sheets(1).Activate
Rows("3:4").Delete 'Deletes blank lines from template
結束子