|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
后来想了一下,把原来的代码稍作修改,代码的速度至少还可以提升10倍。
- Public Sub CreateSalarySheet()
- Dim LastRow As Long, TempRow As Long
- Dim LastColumn As Integer
- On Error Resume Next
- Dim sh As Worksheet, arr
- Set sh = Sheets("工资条")
- If Err.Number = 9 Then '可以利用下标越界错误捕获来判断“工资条”这个工作表是否存在
- Set sh = Sheets.Add(after:=Worksheets("工资表"))
- sh.Name = "工资条"
- End If
- sh.Cells.Clear '先清除所有内容
- With Worksheets("工资表") '先确定区域工资表行列区域
- LastRow = .[a65536].End(xlUp).Row
- LastColumn = .[iv1].End(xlToLeft).Column
- arr = .Range(.[a1], .Cells(LastRow, LastColumn)).Value
- End With
- Dim i As Long, m As Integer, brr()
- ReDim brr(1 To 3 * LastRow - 3, 1 To LastColumn)
- sh.Columns(1 & ":" & LastColumn).ColumnWidth = 10.63
- With sh '把这个添加边框提出来,先在1到3行添加一个边框模板
- .Range(.Cells(1, 1), .Cells(2, LastColumn)).Borders.LineStyle = xlContinuous '设置整体边框的框线类型
- .Range(.Cells(1, 1), .Cells(2, LastColumn)).Borders.ColorIndex = xlAutomatic '设置整体边框的颜色
- .Range(.Cells(1, 1), .Cells(2, LastColumn)).BorderAround Weight:=xlMedium '设置外围边框的粗细
- .Range(.Cells(1, 1), .Cells(3, LastColumn)).Copy .Range(.Cells(4, 1), .Cells(3 * LastRow - 3, LastColumn)) '然后在需要的区域,一次性添加完边框
- End With
- For i = 2 To LastRow
- For m = 1 To LastColumn
- brr(i * 3 - 5, m) = arr(1, m)
- brr(i * 3 - 4, m) = arr(i, m)
- Next m, i
- sh.[a1].Resize(LastRow * 3 - 3, LastColumn) = brr '在这里添加数据即可!
- End Sub
复制代码
[ 本帖最后由 unsamesky 于 2010-11-23 14:41 编辑 ] |
|