循环遍历名称并删除那些不匹配指定名称的名称

时间:2014-06-25 14:08:02

标签: named-ranges

我尝试从此问答中实施解决方案:loop through names and delete those not matching specified pattern并继续收到错误消息。您可以在此包含的AND语句数量是否有限制?

Sub DeleteBCEDetailNames()

Dim myName As Name
For Each myName In ThisWorkbook.Names

If myName.NameLocal <> "bce_bid_country" And
myName.NameLocal <> "bce_Currency" And
myName.NameLocal <> "bce_Exchange_Rate_to_GBP" And
myName.NameLocal <> "bce_Siebel_ID" And
myName.NameLocal <> "bce_Bid_ID" And
myName.NameLocal <> "bce_MP_Authorised_Budget" And
myName.NameLocal <> "bce_Bid_Start_Date" And
myName.NameLocal <> "bce_Make_Pursuit_Date" And
myName.NameLocal <> "bce_Qualification_Bid_SignOn_Date" And
myName.NameLocal <> "bce_Mid_Point_Review_Date" And
myName.NameLocal <> "bce_Bid_Sign_Off_1_Date" And
myName.NameLocal <> "bce_Bid_Sign_Off_2_Date" And
myName.NameLocal <> "bce_Bid_Sign_Off_3_Date" And
myName.NameLocal <> "bce_Contract_Sign_Off_Date" And
myName.NameLocal <> "bce_Expected_Close_Date" And
myName.NameLocal <> "bce_WD_BS_MP" And
myName.NameLocal <> "bce_WD_MP_QBSO" And
myName.NameLocal <> "bce_WD_QBSO_MPR" And
myName.NameLocal <> "bce_WD_MPR_BSOff1" And
myName.NameLocal <> "bce_WD_BSOff1_BSOff2" And
myName.NameLocal <> "bce_WD_BSOff2_BSOff3" And
myName.NameLocal <> "bce_WD_BSOff_CSO" And
myName.NameLocal <> "bce_WD_CSO_ECD" And
myName.NameLocal <> "bce_Total_Working_Days" And
myName.NameLocal <> "bce_Labour_BS_MP" And
myName.NameLocal <> "bce_Labour_MP_QBSO" And
myName.NameLocal <> "bce_Labour_QBSO_MPR" And
myName.NameLocal <> "bce_Labour_MPR_BSOff" And
myName.NameLocal <> "bce_Labour_BSOff_CSO" And
myName.NameLocal <> "bce_Labour_CSO_ECD" And
myName.NameLocal <> "bce_Non_Labour_BS_MP" And
myName.NameLocal <> "bce_Non_Labour_MP_QBSO" And
myName.NameLocal <> "bce_Non_Labour_QBSO_MPR" And
myName.NameLocal <> "bce_Non_Labour_MPR_BSOff" And
myName.NameLocal <> "bce_Non_Labour_BSOff_CSO" And
myName.NameLocal <> "bce_Non_Labour_CSO_ECD" And
myName.NameLocal <> "bce_TotalStageCost_BS_MP" And
myName.NameLocal <> "bce_TotalStageCost_MP_QBSO" And
myName.NameLocal <> "bce_TotalStageCost_QBSO_MPR" And
myName.NameLocal <> "bce_TotalStageCost_MPR_BSOff" And
myName.NameLocal <> "bce_TotalStageCost_BSOff_CSO" And
myName.NameLocal <> "bce_TotalStageCost_CSO_ECD" And
myName.NameLocal <> "bce_Labour_BidSupportCost" And
myName.NameLocal <> "bce_Labour_Bought_inCost" And
myName.NameLocal <> "bce_Labour_SectorCost" And
myName.NameLocal <> "bce_Total_LabourCost" And
myName.NameLocal <> "bce_Non_Labour_PeopleRelatedCost" And
myName.NameLocal <> "bce_Non_Labour_OtherCost" And
myName.NameLocal <> "bce_Total_Non_LabourCost" And
myName.NameLocal <> "bce_Total_BCE_ExcludingOverhead" And
myName.NameLocal <> "bce_Labour_OverheadCost" And
myName.NameLocal <> "bce_Fixed_Charge_per_FTECost" And
myName.NameLocal <> "bce_Total_Overhead_Estimate" And
myName.NameLocal <> "bce_Total_BCE" And
myName.NameLocal <> "bce_BCE_PercentofTOV" And
myName.NameLocal <> "bce_BCE_PercentofICV" Then
my.Name.Delete
End If

Next
End Sub

0 个答案:

没有答案