返回首页
当前位置: 主页 > Excel教程 > Excel2003教程 >

Excel制作工资条的多种方法收集大全(2)

时间:2013-03-07 23:22来源:Office教程学习网 www.office68.com编辑:麦田守望者

Excel中利用宏命令制作工资条二

在日常应用中,我们经常遇到这样的操作,每隔相等的几行,要重复做相同的事情。比如做工资条要打印时,每条记录前插入一个标题列;每隔N行的行高,统一调整为X高等。用常规的操作,如果数据少的话还可以承受,但数据量一大,就变成一件苦差事了。

下面这个宏,能够按指定的选择来选择等差行,选选择N至N+M行,然后再运行此宏,就可以选择从N行开始,每隔M行至到数据结束的行了,代码如下:

 

SubSelectRange()
'按选择区域给定参数选择等差行
DimiAsInteger,XRanAsRange
IfSelection.Areas.Count
>1Then
MsgBox"选择区域应为连续区域!",vbExclamation,"错误"
ElseIfSelection.Row
>ActiveSheet.UsedRange.Rows.CountThen
MsgBox"选择区域应在使用区域内!",vbExclamation,"错误"
Else
SetXRan
=Rows(Selection.Row)
Fori
=Selection.Row+Selection.Rows.CountTo_
ActiveSheet.UsedRange.Rows.CountStepSelection.Rows.Count
SetXRan
=Union(XRan,Rows(i))
Next
XRan.Select
EndIf

 

Excel中利用宏命令制作工资条三

 

AttributeVB_Name="模块1"
Sub生成工资条()
Cells.Select
'选择整个表去掉表格线
Range("F1").Activate
Selection.Borders(xlDiagonalDown).LineStyle
=xlNone
Selection.Borders(xlDiagonalUp).LineStyle
=xlNone
Selection.Borders(xlEdgeLeft).LineStyle
=xlNone
Selection.Borders(xlEdgeTop).LineStyle
=xlNone
Selection.Borders(xlEdgeBottom).LineStyle
=xlNone
Selection.Borders(xlEdgeRight).LineStyle
=xlNone
Selection.Borders(xlInsideVertical).LineStyle
=xlNone
Selection.Borders(xlInsideHorizontal).LineStyle
=xlNone
Rows(
"2:2").Select
'选择第2行
Selection.InsertShift:=xlDown
'在第2行前插入一行,保持第2行为选中状态
num=((ActiveSheet.UsedRange.Rows.Count)-2)*3
'这个数字是工资表中总人数乘以3,例如工资表中有20人,就是num=60
col=ActiveSheet.UsedRange.Columns.Count
'这个数字是工资表中的列数,例如工资表中有20列,就是col=20
num1=4
DoWhilenum1
<=num
'循环插入空行
Range(Cells(num1,1),Cells(num1,col)).Select
'选中第num1行的第1列到第col列
Selection.InsertShift:=xlDown
Selection.InsertShift:
=xlDown
num1
=num1+3
Loop
Range(Cells(
1,1),Cells(1,col)).Select
Application.CutCopyMode
=False
'剪切复制模式无效
Selection.Copy
'复制选择区域
Range("A2").Select
'选择A2单元格
ActiveSheet.Paste
'从A2单元格起粘贴内容
num2=5
DoWhilenum2
<=num
'循环插入标题行
Range(Cells(1,1),Cells(1,col)).Select
Application.CutCopyMode
=False
Selection.Copy
Cells(num2,
1).Select
ActiveSheet.Paste
num2
=num2+3
Loop
Range(Cells(
2,1),Cells(3,col)).Select
Application.CutCopyMode
=False
Selection.Borders(xlDiagonalDown).LineStyle
=xlNone
'定义表格边框线、内线样式
Selection.Borders(xlDiagonalUp).LineStyle=xlNone
WithSelection.Borders(xlEdgeLeft)
.LineStyle
=xlDouble
.Weight
=xlThick
.ColorIndex
=xlAutomatic
EndWith
WithSelection.Borders(xlEdgeTop)
.LineStyle
=xlDouble
.Weight
=xlThick
.ColorIndex
=xlAutomatic
EndWith
WithSelection.Borders(xlEdgeBottom)
.LineStyle
=xlDouble
.Weight
=xlThick
.ColorIndex
=xlAutomatic
EndWith
WithSelection.Borders(xlEdgeRight)
.LineStyle
=xlDouble
.Weight
=xlThick
.ColorIndex
=xlAutomatic
EndWith
WithSelection.Borders(xlInsideVertical)
.LineStyle
=xlDash
.Weight
=xlThin
.ColorIndex
=xlAutomatic
EndWith
WithSelection.Borders(xlInsideHorizontal)
.LineStyle
=xlDash
.Weight
=xlThin
.ColorIndex
=xlAutomatic
EndWith
Selection.Copy
Range(Cells(
5,1),Cells(6,col)).Select
Selection.PasteSpecialPaste:
=xlFormats,Operation:=xlNone,SkipBlanks:=False,Transpose:=False
'接上行删除上行尾的连字符_,复制表格线样式
num3=8
DoWhilenum3
<=num
'循环复制表格线样式
Range(Cells(num3,1),Cells(num3+1,col)).Select
Selection.PasteSpecialPaste:
=xlFormats,Operation:=xlNone,SkipBlanks:=False,Transpose:=False
num3
=num3+3
Loop
Rows(
"1:1").Select
'删除多余的一行
Selection.Delete
EndSub

 

利用Excel强大的数据处理和打印输出功能制作工资条,加快了制作工资条的效率,也减少了手工制作工资条出现的错误,使用起来还是非常方便的。

------分隔线----------------------------
标签(Tag):excel excel2007 excel2010 excel2013 excel2003 excel技巧 excel教程 excel实例教程
------分隔线----------------------------
推荐内容
猜你感兴趣