用EXCEL宏实现工资表巧转工资条

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

用E X C E L宏实现工资表

巧转工资条

Modified by JEEP on December 26th, 2020.

用Excel宏实现工资表巧转工资条

赛迪网--中国电脑教育报

文/邓亚思

Excel具有强大的数据处理和打印输出功能,并且易学易用,是广大用户喜欢使用的电子表格处理软件。现在一些单位的财会人员喜欢用Excel打印本单位的职工工资总表与工资条,但在Excel中要将工资总表(如表1)手工地转换为工资条(如表2)则是一件比较烦琐的事,下面是我编写的一个Excel宏,运行这个宏就可将编辑好了的工资总表很方便地转换为工资条打印输出。

在Excel中新建一个文件,将其命名为“工资表与工资条”,在工作表“sheet1”中输入并编辑好本单位职工工资总表(如表1所示)后,点击“工具”菜单→“宏”→“宏…”→输入宏名“生成工资条”→创建,输入如下的宏的各行文本,输入完成后保存该宏。将工作表“sheet1”复制为另一个工作表“sheet2”中,使“sheet2”成为当前工作表,执行刚才创建的宏,即可很快将表1所示的工资表转换为表2所示的工资条。

宏的内容如下:

Sub 生成工资条()

'选择整个表去掉表格线

Range("F1").Activate

(xlDiagonalDown).Line

Style = xlNone

(xlDiagonalUp).LineStyle = xlNone

(xlEdgeLeft).LineStyle = xlNone

(xlEdgeTop).LineStyle = xlNone (xlEdgeBottom).LineStyle = xlNone (xlEdgeRight).LineStyle = xlNone (xlInsideVertical).LineStyle = xlNone (xlInsideHorizontal).LineStyle = xlNone Rows("2:2").Select

'选择第2行

Shift:=xlDown

'在第2行前插入一行,保持第2行

为选中状态

num=150

'总人数×3,如工资表中有100人则

为100×3即num=300

col=14

'工资表的栏数,如工资表有17栏则

'col=17

num1 = 4

Do While num1 <= num

'循环插入空行

Range(Cells(num1, 1), Cells(num1, col)).Select '选中第num1行的第1列到第col列

Shift:=xlDown

Shift:=xlDown

num1 = num1 + 3

Loop

Range(Cells(1, 1), Cells(1, col)).Select

= False

'剪切复制模式无效

'复制选择区域

Range("A2").Select

'选择A2单元格

'从A2单元格起粘贴内容

num2 = 5

Do While num2 <= num

'循环插入标题行

Range(Cells(1, 1), Cells(1, col)).Select = False

Cells(num2, 1).Select

num2 = num2 + 3

Loop

Range(Cells(2, 1), Cells(3, col)).Select = False

(xlDiagonalDown).LineStyle

= xlNone

'定义表格边框线、内线样式(xlDiagonalUp).LineStyle = xlNone

With (xlEdgeLeft)

.LineStyle = xlDouble

.Weight = xlThick

.ColorIndex = xlAutomatic End With

With (xlEdgeTop)

.LineStyle = xlDouble

.Weight = xlThick

.ColorIndex = xlAutomatic End With

With (xlEdgeBottom)

.LineStyle = xlDouble

.Weight = xlThick

.ColorIndex = xlAutomatic End With

With (xlEdgeRight)

.LineStyle = xlDouble

.Weight = xlThick

.ColorIndex = xlAutomatic

End With

With (xlInsideVertical)

.LineStyle = xlDash

.Weight = xlThin

.ColorIndex = xlAutomatic

End With

With (xlInsideHorizontal)

.LineStyle = xlDash

.Weight = xlThin

.ColorIndex = xlAutomatic

End With

Range(Cells(5, 1), Cells(6, col)).Select

Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False

'接上行删除上行尾的连字符

相关文档
最新文档