|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师不敢当,你提问题我练手.我又尝试编了一三段代码,不用字典,不用数组,实现合并\排序\拆分\删除四大功能,
貌似小数的问题也没问题.代码如下:
- Sub 合并排序拆分多表()
- '合并AB两列数据,B列放到A列尾部,c列分数相对应每个姓名
- Sheets("Sheet1").Activate
- Range("H:I").ClearContents
- [H1:I1] = Array("姓名", "分数")
- endrow = Cells(Rows.Count, "A").End(xlUp).Row
- For i = 0 To 1
- r = i * (endrow - 1)
- Range([a2], "A" & endrow).Offset(0, i).Copy Range("H2").Offset(r, 0)
- Range([a2], "A" & endrow).Offset(0, 2).Copy Range("I2").Offset(r, 0)
- Next i
- [H2].CurrentRegion.Sort key1:=[I2], order1:=2, Header:=xlNo '排序
- Call 删除分表
- Call 拆分到多表
- End Sub
- Sub 拆分到多表()
- Dim sht_name As New Collection, i, T
- Sheets("Sheet1").Activate
- endrow = Cells(Rows.Count, "I").End(xlUp).Row
- For i = 2 To endrow '以分数段取表名
- T = (Cells(i, "I") \ 10) * 10
- Cells(i, "J") = T
- On Error Resume Next
- sht_name.Add T, CStr(T)
- Next
- For Each T In sht_name '建立分表
- Worksheets.Add(after:=Sheets(Sheets.Count)).Name = T
- Next
- For i = 2 To Sheets.Count
- Sheets("Sheet1").Range("H1:J" & endrow).AutoFilter Field:=3, Criteria1:=Sheets(i).Name
- Sheets("Sheet1").Range("H1:I" & endrow).Copy Sheets(i).Range("a1")
- Next
- Sheets("Sheet1").Range("H1:I" & endrow).AutoFilter
- Sheets("Sheet1").Range("J1:J" & endrow).Clear
- Sheets("Sheet1").Select
- Beep
- MsgBox "已处理完毕!"
- End Sub
- Sub 删除分表()
- Sheets("Sheet1").Activate
- Application.DisplayAlerts = False
- For Each sht In Worksheets
- If sht.Name <> "Sheet1" Then sht.Delete
- Next
- Application.DisplayAlerts = True
- End Sub
复制代码
|
|