ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:17.89KB ,
资源ID:6121696      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6121696.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Excel VBA编程实例.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Excel VBA编程实例.docx

1、Excel VBA编程实例Sub direct_Price()定义变量Dim cRows As Integer 总行数Dim cColumns As Integer 总列数Dim HEADERCOLORINDEX As Integer 表头的背景色Dim cTemp As Integer 临时计数Dim sTempString As String 临时字符串变量Dim i As Integer 临时计数Dim j As Integer 临时计数Dim rowIndex As Integer 临时指示处理到哪里Dim colIndex As Integer 临时指示处理到哪里Dim tempRn

2、dColor As Integer 临时生成的颜色Dim TABLENAME As String 待处理的表名 Dim colorIndex As String 颜色索引名字表头的背景色HEADERCOLORINDEX = 15colorIndex = 36 颜色从33开始是比较浅的颜色TABLENAME = direct_Price关闭所有弹出的警告消息Application.DisplayAlerts = False设置需要处理的单元表Sheets(TABLENAME).Select 取单元表的总列数与总行数cRows = Sheets(TABLENAME).UsedRange.Rows.

3、CountcColumns = Sheets(TABLENAME).UsedRange.Columns.CountEOIuB。 选择所有的单元格 Range(Cells(1, 1), Cells(cRows, cColumns).Select 设置该表中所有单元行高为11.25 Selection.RowHeight = 11.25 设置该表中所有单元行高为11.25 Selection.RowHeight = 11.25 设置所有的边框 Selection.Borders(xlDiagonalDown).LineStyle = xlNoneS2rLG。 Selection.Borders(x

4、lDiagonalUp).LineStyle = xlNone 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) .LineS

5、tyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End

6、With 并且拆分所有的单元格 With Selection .MergeCells = False 拆分单格 End With Columns(C:C).Select Selection.Insert Shift:=xlToRight 删除第一列,注意这里必须先拆分单格,再删除第一列,否则一次就会把合并单元格所在列全部删除 Range(Cells(1, 1), Cells(1, 1).Select Selection.EntireColumn.Delete Selection.EntireColumn.Delete 向表头添加一行 Rows(1:1).Select Selection.Ins

7、ert Columns(A:A).SelectSelection.ColumnWidth = 9.29Columns(B:B).SelectSelection.ColumnWidth = 6.71Columns(C:C).SelectSelection.ColumnWidth = 15.29Columns(D:D).SelectSelection.ColumnWidth = 29.86Columns(E:E).SelectSelection.ColumnWidth = 12.29Columns(F:F).SelectSelection.ColumnWidth = 12.29 设定单元格A1:A

8、2 合并A1:A2单元格 Range(A1:A2).Select 将数据写回 With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With 往该单元格中写入Usage_Var ActiveCell.FormulaR1C1 = Price 设置该单元格字

9、体格式 With ActiveCell.Characters(Start:=1, Length:=5).FontW0A7c。 .Name = Arial .FontStyle = 加粗 倾斜 .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = 2 End With 单元格设定边框 Selection.Borders(xlDiagon

10、alDown).LineStyle = xlNonefOxR7。 Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = 56 End With Selection.Borders(xlInsideHorizontal).LineStyle = xlNonefGaap。

11、 With Selection.Interior .colorIndex = 5 .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With 设定头两行的内部样式 Range(B1:B2).Select Selection.Merge Range(C1:C2).Select Selection.Merge Range(D1:D2).Select Selection.Merge Range(B1:D2).Select 设置头两行行高为11.25 Selection.RowHeight = 14.25 With Selection.Fo

12、nt .Name = Arial .FontStyle = 加粗 .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = xlAutomatic End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText =

13、 True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext End With With Selection.Interior .colorIndex = HEADERCOLORINDEX .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With Range(B1:B2).Select ActiveCell.FormulaR1C1 = Type With ActiveCell.Cha

14、racters(Start:=1, Length:=4).Font9SEMC。 .Name = Arial .FontStyle = 加粗 .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = 5 End With Range(E1:F1).Select With Selection.Font .Name = Arial .FontSt

15、yle = 加粗 .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = 5 End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .AddIndent

16、= False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With With Selection.Interior .colorIndex = HEADERCOLORINDEX .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With ActiveCell.FormulaR1C1 = Price Range(E2:F2).Select 设置头两行行高为11.25 Selection.RowHeight

17、 = 14.25 With Selection.Font .Name = Arial .FontStyle = 加粗 .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = xlAutomatic End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignm

18、ent = xlCenter .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With With Selection.Interior .colorIndex = HEADERCOLORINDEX .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With 加第一二行边框 Range(A1:F2).Se

19、lect Selection.Borders(xlDiagonalDown).LineStyle = xlNonehOUNi。 Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xl

20、Thin .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 With Selection.Borders(xlInside

21、Vertical) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = xlAutomatic End With 去掉第三行的:号 sTempString = Right(Cells(3, 1), Len(Cells(3, 1) - 3)GiwW2。 ActiveCell.FormulaR1C1

22、 = sTempString i = 2 j = 1 外层循环判断是否都合并完成,这里插入了一行,加1 While i = 3) Then 如果是分格的界限 If (Left(Cells(i + 1, j), 3) = : ) Then Range(Cells(i + 1, j), Cells(i + 1, cColumns).SelectxtwBS。 对第三行进行设定 设置头两行行高为11.25 Selection.RowHeight = 18 With Selection.Interior .colorIndex = 2 .Pattern = xlSolid .PatternColorIn

23、dex = xlAutomatic End With 合并前两格 先将其合并 With Selection .HorizontalAlignment = xlLeft 靠左对齐 .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With 合并 Selection.Merge 对其设定字体风格 With Selection.Font .Name = Arial .FontStyle = 加粗 倾斜 .

24、Size = 9 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = 3 End With With Selection .HorizontalAlignment = xlLeft .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .AddIndent = False .Ind

25、entLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With sTempString = Right(Cells(i + 1, j), Len(Cells(i + 1, j) - 3)OXPTP。 ActiveCell.FormulaR1C1 = sTempString i = i + 1 End If End If i = i + 1 加1后判断是否到了表尾,没有继续合并处理 If (i = cRows + 1) Then rowIndex = i 取出Cells(i, j)的内

26、容 sTempString = Cells(i, j) 循环判断下一个单元格是否和上一个单元格相等,不是则表示到此该合并 While sTempString = Cells(i + 1, j) And i = cRows i = i + 1 Wend 设置第一列 跳出循环表示已经到此该将rowIndex 和 i行合并 Range(Cells(rowIndex, j), Cells(i, j).Select Selection.Merge 将原来内容填充进来 ActiveCell.FormulaR1C1 = sTempString 设合并后的单元格的边框 With Selection .Hori

27、zontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With Selection.Font.FontStyle = 加粗 设置第一列结束 设置第二列 Range(Cells(rowIndex, j + 1), Cells(i, j + 1).SelectMe

28、x62。 设置字体 With Selection.Font .Name = Arial .FontStyle = 加粗 .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .colorIndex = 5 End With With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlC

29、enter .WrapText = True .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Borders(xlDiagonalDown).LineStyle = xlNoneh7pGG。 Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weigh

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1