|
前因:每个月都要求全部门同事上交一份excel交代自己做了什么,希望能查出谁没有交,希望能自动把各excel的值赋值集成到一张总表上。
求问1:如何获取各excel工作簿的文件名,使之成为一列,这样我就可以筛选重复值,来查出谁没有交。
2013年6月.zip
(790.07 KB, 下载次数: 2)
eg:文件夹中有曾思敏、陈聪 两个excel表格,在一空表中输入vba,能直接在A:A上显示出 A1曾思敏 A2 陈聪……
求问2:优化代码,用 for i=1 的语句优化我宏1的代码,使运行速度加快,出现错误率低。
文件夹中有一文件:运行研发部2013年X月技术人员考核统计表.xlsm,
查看vbe能够发现,我的模块一代码其实很繁琐,能否优化。 (PS:我之所以用indirect转值是为了方便更改,您知道有些人员变动,能方便更改,还有 Sheets("潘顺娥").[D2] = wkSht.[D2]
Sheets("潘顺娥").[G2] = wkSht.[G2]之所以类似这样赋值,是因为有些员工交表不是按统一模板,如果直接取值容易发生错误值)
求问3:该添加一个什么语句,让自动跳转下一个指令
eg:朱尔琴下有三人:刘志恒、姚学铜、钟晶,我运行命令时,一旦刘志恒没有搜索到,则姚学铜、钟晶的分数亦不能获取。代码如下:
Sub getmark_zhuerqin() '获取朱尔琴下层级3人的分数
Dim myApp As New Application, wkSht As Worksheet
'隐藏Excel
myApp.Visible = False
'打开刘志恒表,并指定工作表对象
Set wkSht = myApp.Workbooks.Open(ThisWorkbook.Path & "\刘志恒.xls").Sheets(1)
Sheets("刘志恒").[D2] = wkSht.[D2]
Sheets("刘志恒").[G2] = wkSht.[G2]
Sheets("刘志恒").[I2] = wkSht.[I2]
Sheets("刘志恒").[K2] = wkSht.[K2]
Sheets("刘志恒").[F3] = wkSht.[F3]
Sheets("刘志恒").[F4] = wkSht.[F4]
Sheets("刘志恒").[F5] = wkSht.[F5]
Sheets("刘志恒").[K10] = wkSht.[K10]
Sheets("刘志恒").[K11] = wkSht.[K11]
Sheets("刘志恒").[K12] = wkSht.[K12]
Sheets("刘志恒").[K13] = wkSht.[K13]
Sheets("刘志恒").[K14] = wkSht.[K14]
Sheets("刘志恒").[K15] = wkSht.[K15]
Sheets("刘志恒").[K16] = wkSht.[K16]
Sheets("刘志恒").[K17] = wkSht.[K17]
Sheets("刘志恒").[K18] = wkSht.[K18]
Sheets("刘志恒").[K19] = wkSht.[K19]
Sheets("刘志恒").[E20] = wkSht.[E20]
'关闭Excel
myApp.Quit
'打开姚学铜表,并指定工作表对象
Set wkSht = myApp.Workbooks.Open(ThisWorkbook.Path & "\姚学铜.xls").Sheets(1)
Sheets("姚学铜").[D2] = wkSht.[D2]
Sheets("姚学铜").[G2] = wkSht.[G2]
Sheets("姚学铜").[I2] = wkSht.[I2]
Sheets("姚学铜").[K2] = wkSht.[K2]
Sheets("姚学铜").[F3] = wkSht.[F3]
Sheets("姚学铜").[F4] = wkSht.[F4]
Sheets("姚学铜").[F5] = wkSht.[F5]
Sheets("姚学铜").[K10] = wkSht.[K10]
Sheets("姚学铜").[K11] = wkSht.[K11]
Sheets("姚学铜").[K12] = wkSht.[K12]
Sheets("姚学铜").[K13] = wkSht.[K13]
Sheets("姚学铜").[K14] = wkSht.[K14]
Sheets("姚学铜").[K15] = wkSht.[K15]
Sheets("姚学铜").[K16] = wkSht.[K16]
Sheets("姚学铜").[K17] = wkSht.[K17]
Sheets("姚学铜").[K18] = wkSht.[K18]
Sheets("姚学铜").[K19] = wkSht.[K19]
Sheets("姚学铜").[E20] = wkSht.[E20]
'关闭Excel
myApp.Quit
'打开钟晶表,并指定工作表对象
Set wkSht = myApp.Workbooks.Open(ThisWorkbook.Path & "\钟晶.xls").Sheets(1)
Sheets("钟晶").[D2] = wkSht.[D2]
Sheets("钟晶").[G2] = wkSht.[G2]
Sheets("钟晶").[I2] = wkSht.[I2]
Sheets("钟晶").[K2] = wkSht.[K2]
Sheets("钟晶").[F3] = wkSht.[F3]
Sheets("钟晶").[F4] = wkSht.[F4]
Sheets("钟晶").[F5] = wkSht.[F5]
Sheets("钟晶").[K10] = wkSht.[K10]
Sheets("钟晶").[K11] = wkSht.[K11]
Sheets("钟晶").[K12] = wkSht.[K12]
Sheets("钟晶").[K13] = wkSht.[K13]
Sheets("钟晶").[K14] = wkSht.[K14]
Sheets("钟晶").[K15] = wkSht.[K15]
Sheets("钟晶").[K16] = wkSht.[K16]
Sheets("钟晶").[K17] = wkSht.[K17]
Sheets("钟晶").[K18] = wkSht.[K18]
Sheets("钟晶").[K19] = wkSht.[K19]
Sheets("钟晶").[E20] = wkSht.[E20]
'关闭Excel
myApp.Quit
Set wkSht = Nothing
Set myApp = Nothing
End Sub
这三个问题,求解,谢谢。本人还是菜鸟,因基础较烂,如果问得不当,请海涵。
|
|