ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 5076|回复: 9

抛砖引玉----自己编的小宏

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-11-25 08:53 | 显示全部楼层 |阅读模式

3rElejGc.rar (10.53 KB, 下载次数: 42)

这是我自己不断摸索编的小宏,从不知道到知道,可能对一些想要学习编宏的比较有用。代码很简单,适合初学者。

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-11-25 08:55 | 显示全部楼层

Sub 边框() Dim i, n

Range("b1").Formula = "=counta(r[1])" i = Range("b1").Value

For n = 1 To (i - 1) / 3

Range(Cells(3, n * 3 - 1), Cells(17, n * 3 + 1)).Select 加边框 Range(Cells(1, n * 3 - 1), Cells(2, n * 3 + 1)).Select 加边框

Next n Range("a1:a2,a3:a17").Select 加边框 Range("b1").Clear End Sub

Sub 加边框() rem 这里完全是录的,对于初学者录宏是一个很好的学习的方法。

With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous '.Weight = xlThin '.ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous '.Weight = xlThin '.ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous '.Weight = xlThin '.ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous '.Weight = xlThin '.ColorIndex = xlAutomatic End With Selection.Borders(xlInsideHorizontal).LineStyle = xlNone

End Sub

TA的精华主题

TA的得分主题

发表于 2005-11-25 09:20 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

我写的,好像比楼主的更麻烦一点,呵呵

Sub hjs() Dim irow%, icol%, j%

Application.ScreenUpdating = False With Range("a2").CurrentRegion irow = .Rows.Count '当前区域行的总数 icol = .Columns.Count '当前区域列的总数 .Borders.LineStyle = xlNone '清除当前区域所有的边框 End With

Add_border Cells(1, 1).Resize(2, 1) '增加a1:b1的边框 Add_border Cells(3, 1).Resize(irow - 2, 1) '增加a3和下面单元格的边框 For j = 2 To icol Step 3 '每3列循环一次,增加边框 Add_border Cells(1, j).Resize(2, 3) Add_border Cells(3, j).Resize(irow - 2, 3) Next End Sub

Sub Add_border(rng As Range) '加边框,上下左右四边 With rng .Borders(xlEdgeLeft).LineStyle = xlContinuous '左 .Borders(xlEdgeTop).LineStyle = xlContinuous '上 .Borders(xlEdgeBottom).LineStyle = xlContinuous '下 .Borders(xlEdgeRight).LineStyle = xlContinuous '右 End With End Sub

TA的精华主题

TA的得分主题

发表于 2005-11-25 09:20 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

加边框的代码可精简为: selection.Borders.LineStyle = xlContinuous

TA的精华主题

TA的得分主题

发表于 2005-11-25 09:23 | 显示全部楼层

关于楼主i的使用,可以直接这样。

i = Application.WorksheetFunction.CountA(Rows(2))

调用工作表函数counta

TA的精华主题

TA的得分主题

发表于 2005-11-25 09:58 | 显示全部楼层

weight或linestyle默识是加四边框,不管指定线条样式或线宽都会加上四周框线

有兴趣可测试下面程式码:

Sub xx() [d3].Borders.Weight = xlMedium [d5].Borders.LineStyle = xlContinuous [d7].Borders.Weight = xlThin [d9].Borders(1).Weight = xlMedium [d11].Borders(2).Weight = xlMedium [d13].Borders(3).Weight = xlMedium [d15].Borders(4).Weight = xlMedium [d17].Borders(5).Weight = xlMedium End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-11-25 10:00 | 显示全部楼层

我写的,好像比楼主的更麻烦一点,呵呵

太谦虚了,LONGIII兄,,

[em04]

不过3、4楼的语句一定记下!!!

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-11-25 10:06 | 显示全部楼层
我现在编的宏都是自己公司用(主要是我自己用),所以目前的要求是能实现就行。不过看了各位高手的代码后确实效果非常好。有一个我编的商品进销存宏,运行时间要30秒还多。。不知道怎么样可以精简一点,努力学习中。。。。

TA的精华主题

TA的得分主题

发表于 2005-11-25 11:18 | 显示全部楼层

录制宏的效率是很低,要学会怎么修改代码!

经常来论坛学习,慢慢就知道怎么提速了

TA的精华主题

TA的得分主题

发表于 2005-12-14 10:39 | 显示全部楼层
是中.錄制宏的效率低﹐并且功能也有很大的局限性﹐要真正達到好用的目的﹐還得編寫代碼。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-4 04:12 , Processed in 0.037730 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表