这是我加入以来的第一篇文章。我已经搜索了答案,但如果它已经存在那么就无法找到它。
情况就是这样。
我有一个包含大量表格的Excel工作簿。 我编写了一个宏,它将指定范围从此主工作簿复制到新工作簿(对于区域管理器,因此它们的副本仅包含其数据)。范围包含表格。第一个工作表包含4个表。前两个表始终粘贴,底部2,grrrr,有时粘贴为表格,有时不粘贴! 有两行代码可以过滤这些底部的2个表。当他们粘贴为表格时它很好,但是当它们不粘时它不起作用。 我已经输入了“错误”,以便宏继续并完成,并且没关系。
令人讨厌的是,当他们不粘贴为表格时,会有2个单元格出现错误,这是名字和姓氏。
我的问题是.....为什么它有时会粘贴表格,有时候不会???!?!
我的代码如下,非常感谢任何帮助/建议。
P.S对不起,这是一个很长的消息
Sub CreateRMNotification()
Dim Newbook As New Workbook
Dim CommCompRegion As Range
Dim NewRegion As Range
Dim CommCompDaysData As Range
Dim NewDaysData As Range
Dim CommCompPermData As Range
Dim NewPermData As Range
Dim CommCompLeaderboardEDC As Range
Dim NewLeaderboardEDC As Range
Dim CommCompLeaderboardAreaEDC As Range
Dim NewLeaderboardAreaEDC As Range
Dim CommCompLeaderboardLT As Range
Dim NewLeaderboardLT As Range
Dim CommCompLeaderboardAreaLT As Range
Dim NewLeaderboardAreaLT As Range
Dim CommCompResourcer As Range
Dim NewResourcer As Range
Dim RegionName As String
Sheets("RM notification").Select
RegionName = Range("RegionSelect")
Set Newbook = Workbooks.Add
ActiveSheet.Name = "Region"
Sheets("Sheet2").Name = "Days Data"
Sheets("Sheet3").Name = "Perm Data"
If RegionName = "London Region" Or RegionName = "South Region" Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Resourcer Comm"
End If
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Leaderboard EDC"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Leaderboard Area EDC"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Leaderboard LT"
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Leaderboard Area LT"
Set CommCompRegion = ThisWorkbook.Worksheets("RM notification").[A2:Z300]
Set NewRegion = Newbook.Worksheets("Region").[A2:Z300]
Set CommCompDaysData = ThisWorkbook.Worksheets("Days Data").[A2:O80000]
Set NewDaysData = Newbook.Worksheets("Days Data").[A2:O80000]
Set CommCompPermData = ThisWorkbook.Worksheets("Perm Data").[A2:N1000]
Set NewPermData = Newbook.Worksheets("Perm Data").[A2:N1000]
Set CommCompLeaderboardEDC = ThisWorkbook.Worksheets("LeaderboardEDC").[A2:K80]
Set NewLeaderboardEDC = Newbook.Worksheets("Leaderboard EDC").[A2:K80]
Set CommCompLeaderboardAreaEDC = ThisWorkbook.Worksheets("LeaderboardAreaEDC").[A2:G400]
Set NewLeaderboardAreaEDC = Newbook.Worksheets("Leaderboard Area EDC").[A2:G400]
Set CommCompLeaderboardLT = ThisWorkbook.Worksheets("LeaderboardLT").[A2:I100]
Set NewLeaderboardLT = Newbook.Worksheets("Leaderboard LT").[A2:I100]
Set CommCompLeaderboardAreaLT = ThisWorkbook.Worksheets("LeaderboardAreaLT").[A2:K400]
Set NewLeaderboardAreaLT = Newbook.Worksheets("Leaderboard Area LT").[A2:K400]
If RegionName = "London Region" Or RegionName = "South Region" Then
Set CommCompResourcer = ThisWorkbook.Worksheets("ResourcingComm").[A2:R1000]
Set NewResourcer = Newbook.Worksheets("Resourcer Comm").[A2:R1000]
End If
Sheets("Region").Select
CommCompRegion.Copy
NewRegion.PasteSpecial xlPasteColumnWidths
NewRegion.PasteSpecial xlPasteAll
NewRegion.Copy
NewRegion.PasteSpecial xlValues
Application.CutCopyMode = False
On Error Resume Next
ActiveSheet.ListObjects("tblRMNotificationDetail").Range.AutoFilter Field:=1, Criteria1:="<>0"
ActiveSheet.ListObjects("tblRMNotificationDetailRMs").Range.AutoFilter Field:=1, Criteria1:="<>0"
On Error GoTo 0
CommCompDaysData.Copy
NewDaysData.PasteSpecial xlPasteAll
NewDaysData.PasteSpecial xlPasteColumnWidths
NewDaysData.Copy
NewDaysData.PasteSpecial xlValues
Application.CutCopyMode = False
CommCompPermData.Copy
NewPermData.PasteSpecial xlPasteAll
NewPermData.PasteSpecial xlPasteColumnWidths
NewPermData.Copy
NewPermData.PasteSpecial xlValues
Application.CutCopyMode = False
CommCompLeaderboardEDC.Copy
NewLeaderboardEDC.PasteSpecial xlPasteAll
NewLeaderboardEDC.PasteSpecial xlPasteColumnWidths
NewLeaderboardEDC.Copy
NewLeaderboardEDC.PasteSpecial xlValues
Application.CutCopyMode = False
CommCompLeaderboardAreaEDC.Copy
NewLeaderboardAreaEDC.PasteSpecial xlPasteAll
NewLeaderboardAreaEDC.PasteSpecial xlPasteColumnWidths
NewLeaderboardAreaEDC.Copy
NewLeaderboardAreaEDC.PasteSpecial xlValues
Application.CutCopyMode = False
CommCompLeaderboardLT.Copy
NewLeaderboardLT.PasteSpecial xlPasteAll
NewLeaderboardLT.PasteSpecial xlPasteColumnWidths
NewLeaderboardLT.Copy
NewLeaderboardLT.PasteSpecial xlValues
Application.CutCopyMode = False
CommCompLeaderboardAreaLT.Copy
NewLeaderboardAreaLT.PasteSpecial xlPasteAll
NewLeaderboardAreaLT.PasteSpecial xlPasteColumnWidths
NewLeaderboardAreaLT.Copy
NewLeaderboardAreaLT.PasteSpecial xlValues
Application.CutCopyMode = False
If RegionName = "London Region" Or RegionName = "South Region" Then
CommCompResourcer.Copy
NewResourcer.PasteSpecial xlPasteAll
NewResourcer.PasteSpecial xlPasteColumnWidths
NewResourcer.Copy
NewResourcer.PasteSpecial xlValues
Application.CutCopyMode = False
End If
Sheets(Array("Days Data", "Perm Data", "Leaderboard EDC", "Leaderboard Area EDC", "Leaderboard LT", "Leaderboard Area LT")).Select
[B2:O3].Select
Selection.Clear
Sheets.Select
ActiveWindow.Zoom = 85
ActiveWindow.DisplayGridlines = False
[A1].Select
Sheets("Region").Select
End Sub