文章预览
学习Excel技术,关注微信公众号: excelperfect 标签: VBA 如下图 1 所示,列 B 中有一系列重复数据,想要将每个重复的数据所在的行放到一个新工作簿并以该数据作为工作簿名。例如,列 B 中为 7890 的所有行复制到一个新工作簿并命名为 7890.xlsx 。 图 1 这里借用在 vbaexpress.com 中找到的一段程序来实现。 代码如下: Sub test() Dim rng As Range, wbDest As Workbook, wsDest As Worksheet, wsCbasis As Worksheet Dim DTCCstr As Variant, var As Variant, DTCCcol As New Collection, x As Long With Application .EnableAnimations = False .Calculation = xlCalculationManual .ScreenUpdating = False End With Set wsCbasis = Sheets( "源数据" ) With wsCbasis var = .Range( "B2:B" & .Range( "B" & Rows.Count).End(xlUp).Row) For x = 0 To UBound( var ) On Error Resume Next DTCCcol.Add var (x, 1 ), CStr( v
………………………………