简体   繁体   English

过滤并复制到新的工作表(新工作表将按过滤的项目命名)

[英]Filtered and copy to a new sheet (new sheet to be named as per filtered item)

I have a master data which i need to separate into few sheets based on certain criteria and at the same time I would like the new sheet to be renamed to be the same as the criteria. 我有一个主数据,我需要根据某些标准将其分成几张纸,同时我希望将新纸页重命名为与该标准相同。

The VBA code is as below. VBA代码如下。 Any idea that i can change the name "101 transport inc" to follow the name as per Criteria1:=worksheets("CHK").Range("C5") ? 我可以更改名称“ 101 transport inc”以遵循Criteria1:=worksheets("CHK").Range("C5")吗?

Sheets("RAW Data").Select
    ActiveSheet.Range("$A$7:$U$2000").AutoFilter Field:=7, 
Criteria1:=Worksheets("CHK").Range("C5")
    Range("A7").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets.Add(After:=Sheets(Sheets.Count)).Name = "101 Transport Inc"
    ActiveSheet.Paste

.Name property of Worksheets allows you to change the name of a sheet. 工作表的.Name属性允许您更改工作表的名称。 But, take care not to run this twice. 但是,请注意不要重复运行两次。 Once the sheet is renamed, you will get a "Subscript Out of Range'" error if not handled properly. 重命名工作表后,如果处理不当,将出现“下标超出范围”错误。

Sheets("101 Transport Inc").Name = Worksheets("CHK").Range("C5")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM