VBA编程实例

2020-03-27 02:21

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 tempRndColor As Integer '临时生成的颜色 Dim TABLENAME As String '待处理的表名 Dim colorIndex As String '颜色索引名字 '''''''''''''''''''''''''''''''''''''''''''''' '表头的背景色

HEADERCOLORINDEX = 15

colorIndex = 36 '颜色从33开始是比较浅的颜色 TABLENAME = \'关闭所有弹出的警告消息

Application.DisplayAlerts = False '设置需要处理的单元表 Sheets(TABLENAME).Select '取单元表的总列数与总行数

cRows = Sheets(TABLENAME).UsedRange.Rows.Count cColumns = Sheets(TABLENAME).UsedRange.Columns.Count

''''''''''''''''''''''''''''''''''''''''''''''

'选择所有的单元格

Range(Cells(1, 1), Cells(cRows, cColumns)).Select

'设置该表中所有单元行高为11.25 Selection.RowHeight = 11.25

'设置该表中所有单元行高为11.25 Selection.RowHeight = 11.25

'设置所有的边框

Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).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) .LineStyle = 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 With

'并且拆分所有的单元格 With Selection

.MergeCells = False '拆分单格 End With

Columns(\

Selection.Insert Shift:=xlToRight

'删除第一列,注意这里必须先拆分单格,再删除第一列,否则一次就会把合并单元格所在列全部删除

Range(Cells(1, 1), Cells(1, 1)).Select Selection.EntireColumn.Delete 'Selection.EntireColumn.Delete

'向表头添加一行 Rows(\

Selection.Insert

Columns(\Selection.ColumnWidth = 9.29 Columns(\Selection.ColumnWidth = 6.71 Columns(\

Selection.ColumnWidth = 15.29 Columns(\

Selection.ColumnWidth = 29.86 Columns(\

Selection.ColumnWidth = 12.29 Columns(\

Selection.ColumnWidth = 12.29

'''''''''''''''''''''''''''''''''''设定单元格A1:A2'''''''''''''''''''' '合并A1:A2单元格 Range(\

'将数据写回 With Selection

.HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False

.ReadingOrder = xlContext .MergeCells = True End With

'往该单元格中写入Usage_Var ActiveCell.FormulaR1C1 = \

'设置该单元格字体格式

With ActiveCell.Characters(Start:=1, Length:=5).Font .Name = \

.FontStyle = \加粗 倾斜\ .Size = 10

.Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False

.Underline = xlUnderlineStyleNone .colorIndex = 2 End With

'单元格设定边框

Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .colorIndex = 56


VBA编程实例.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:期中卷子

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: