excel分类筛选后生成新表格代码

excel

1个回答

写回答

13705839193

2025-12-21 15:48

+ 关注

excel
excel

如果每个工作表的格式相同,可以使用宏来实现。假设我们要筛选的结果放在A表中,并且姓名位于A列。每个工作表都有连续的数据,且不含公式。以下是一个宏的示例命令:vbnetp = InputBox("输入姓名:", "集中筛选")If Len(p) = 0 Then Exit Subx = 0For Each s In SheetsIf s.Name "A" ThenFor Each c In Range("A:A")If Len(c.Value) = 0 Then Exit ForIf c.Value = p Thenc.Copy Sheets("A").Range("A1").Offset(x, 0)x = x + 1End IfNext cEnd IfNext s如果数据表中包含公式,需要将上述代码中的c.Copy Sheets("A").Range("A1").Offset(x, 0)改为:Sheets("A").Range("A1:X1").Offset(x, 0).Value = s.Range("A1:X1").Offset(c.Row - 1, 0).Value这样才能根据公式计算出结果。注意:以上代码仅适用于excel 2007及以后版本。

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号