我不知道造成这个问题的原因。我有一个简单的宏,它创建新选项卡并命名它们,然后从一个选项卡中过滤数据并将其粘贴到相应的选项卡。
这是我的代码:
Sub Tabs()
Dim wbRecovery As Workbook
Dim wsFac As Worksheet
Set wbRecovery = ThisWorkbook
Set wsFac = wbRecovery.Sheets("Facility Rec Bucket & Year")
With wbRecovery
Sheets.Add After:=Sheets(Sheets.Count), Count:=17
Sheets(5).Name = "DANES"
Sheets(6).Name = "DCEND"
Sheets(7).Name = "DCHED"
Sheets(8).Name = "DCNUR"
Sheets(9).Name = "DCRIC"
Sheets(10).Name = "DEMER"
Sheets(11).Name = "DHEMA"
Sheets(12).Name = "DMED"
Sheets(13).Name = "DNEUR"
Sheets(14).Name = "DNSUR"
Sheets(15).Name = "DOBGY"
Sheets(16).Name = "DOPHT"
Sheets(17).Name = "DPEDS"
Sheets(18).Name = "DPMR"
Sheets(19).Name = "DPSYC"
Sheets(20).Name = "DRADS"
Sheets(21).Name = "DSURG"
End With
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DANES"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DANES").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DCEND"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DCEND").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DCHED"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DCHED").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DCNUR"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DCNUR").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DCRIC"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DCRIC").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DEMER"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DEMER").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DHEMA"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DHEMA").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DMED"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DMED").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DNEUR"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DNEUR").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DNSUR"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DNSUR").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DOBGY"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DOBGY").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DOPHT"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DOPHT").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DPEDS"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DPEDS").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DPMR"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DPMR").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DPSYC"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DPSYC").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DRADS"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DRADS").Range("A1")
wsFac.Range("A1").AutoFilter Field:=1, Criteria1:=("DSURG"), _
Operator:=xlFilterValues
wsFac.Cells.Copy Destination:=wbRecovery.Sheets("DSURG").Range("A1")
End Sub
当我按原样运行此代码时,在粘贴 OBGY 标签后,我收到错误" Excel无法使用可用资源完成任务" 。从中复制数据的选项卡不是异常大,它只有566行和14列宽(我不会认为这对Excel很大)。如果我单独或以5-8的块运行代码行,它就可以完美运行。所有数据都被正确复制和粘贴,但是当我作为一个整体运行时,我遇到了同样的问题。
我的电脑或Excel本身有问题吗?
我从桌面上删除了很多东西,所以我认为这不是存储问题。此外,当我手动执行此过程时,我没有任何问题。我也试过了Application.CutCopyMode = False
,而且还没有用过