|
本帖最后由 qish1888 于 2016-12-26 18:55 编辑
老师们好,我有一个表,每四行为一组,中间空一行。如图,
要求:
1、分类表在同一工作薄下
2、按I、J两列的关健字进行分类。
3、分类工作表的名称=分类名称 如12123131、34341111、12122121
请测试:
- Sub wanao()
- Dim a As String, b As String, sName As Worksheet
- Dim x, shtExist As Boolean
- For x = 3 To Cells(Rows.Count, "a").End(xlUp).Row Step 5
- shtExist = False
- a = Cells(x, "i") & Cells(x + 1, "i") & Cells(x + 2, "i") & Cells(x + 3, "i")
- b = Cells(x, "j") & Cells(x + 1, "j") & Cells(x + 2, "j") & Cells(x + 3, "j")
- For Each sName In Sheets
- aa = sName.Name
- If sName.Name = a & b Or sName.Name = b & a Then
- shtExist = True
- Exit For
- End If
- Next
- If shtExist = True Then
- Rows(x & ":" & x + 3).Copy
- sName.Activate
- Rows(sName.Cells(Rows.Count, "a").End(xlUp).Row + 2).Select
- ActiveSheet.Paste
- ActiveSheet.Name = a & b
- Else
- Rows(x & ":" & x + 3).Select
- Selection.Copy
- Sheets.Add After:=Sheets(Sheets.Count)
- Rows("1:1").Select
- ActiveSheet.Paste
- ActiveSheet.Name = a & b
- End If
- ThisWorkbook.Sheets(1).Activate
-
- Next
- End Sub
复制代码
|
|