好文档 - 专业文书写作范文服务资料分享网站

excel宏教程

天下 分享 时间: 加入收藏 我要投稿 点赞

Excel宏教程

一、 选中单个单元格 Range(“<单元格地址>“).Select

例:Range(\?选中“C9”单元格

二、 选中多个单元格

Range(“<单元格地址>:<单元格地址>[,<单元格地址>……]”).Select

例:Range(“A1:B2”).Select ?选中“A1”、“A2”、“B1”、“B2”四个连续的单元格 Range(“12:12”).Select ?选中第12行 Range(“B:B”).Select ?选中第B列

Range(“A1:A2,B7,2:2”).Select ?选中“A1”、“A2”、“B7”五个不连续的单元格和第二行 Cells.Select ?选中当前SHEET中的所有单元格

Rows(\行地址>:<行地址>\?选中整行 Columns(\列地址>:<列地址>\?选中整列

例:Rows(“2:2”). Select ?选中第2行 Rows(“2:5”). Select ?选中2到5行 Columns(\?选中A列 Columns(\?选中E到B列

三、 设置活动单元格

Range(\单元格地址>\

注:设置活动单元格 与 选中单元格类似,不同之处就是

后者在选中指定的单元格之前会将在此前已被选中的单元格取消掉。 前者在设置之前不会取消已选中的单元格,

如果此时操作的单元格不是被选中的单元格,这时他实现的功能与选一个单元格相同。

四、 给活动的单元格赋值 ActiveCell.FormulaR1C1 = <值>

例:Range(\

ActiveCell.FormulaR1C1 = \Range(\

ActiveCell.FormulaR1C1 = \Range(\Range(\

ActiveCell.FormulaR1C1 = \Range(\

ActiveCell.FormulaR1C1 = \Range(\

ActiveCell.FormulaR1C1 = \Range(\

ActiveCell.FormulaR1C1 = \

五、 得到指定单元格中的值 Range(\单元格地址>\

六、 插入单元格

Selection.Insert Shift:= Selection.EntireRow.Insert Selection.EntireColumn.Insert

例:Selection.Insert Shift:=xlToRight ?在当前选中单元格的位置插入单元格并将当前选中的单元格向右移动

Selection.Insert Shift:=xlDown ?在当前选中单元格的位置插入单元格并将当前选中的单元格向下移动

Selection.EntireRow.Insert ?在当前选中单元格的上面插入一行 Selection.EntireColumn.Insert ?在当前选中单元格的左侧插入一列

七、 设置字体属性 1. 设置字体名称和大小 Selection.Font.Name = <字体名称> Selection.Font.Size = <字号>

例:Selection.Font.Name = \隶书\Selection.Font.Size = 15 2. 设置字体样式

Selection.Font.Bold = ?加粗

Selection.Font.Italic = ?斜体

Selection.Font.Underline = < XlUnderlineStyle(下划线样式)> ?下划线

XlUnderlineStyle(下划线样式): xlUnderlineStyleDouble ?双下划线

xlUnderlineStyleDoubleAccounting ?会计用双下划线(如果当前单元格中的数据是数字时则下划线的宽度是当前单元格的宽度) xlUnderlineStyleNone 没有下划线 xlUnderlineStyleSingle ?单下划线

xlUnderlineStyleSingleAccounting ?会计用单下划线(如果当前单元格中的数据是数字时则下划线的宽度是当前单元格的宽度) 3. 设置字体的颜色

Selection.Font.ColorIndex = <0到56之间的数字> Selection.Font.Color = 4. 设置字体的特殊效果

Selection.Font.Strikethrough = ?删除线 Selection.Font.Superscript = ?上标 Selection.Font.Subscript = ?下标

八、 清空选中单元格里的内容 Selection.ClearContents

例:Range(“A1:A2,B7,2:2”).Select ?选中“A1”、“A2”、“B7”五个不连续的单元格和第二行 Selection.ClearContents ?清空“A1”、“A2”、“B7”五个不连续单元格中的所有内容

九、 设置选中单元格的边线属性 XlBordersIndex(边线): xlEdgeLeft '单元格左边线 xlEdgeTop ?单元格上边线 xlEdgeRight ?单元格右边线 xlEdgeBottom ?单元格下边线

xlDiagonalDown ?单元格左上右下斜线 xlDiagonalUp ?单元格左上右下斜线 xlInsideVertical ?多个单元格内垂直线 xlInsideHorizontal ?多个单元格内水平线

1. 设置边线的类型

Selection.Borders(<边线>).LineStyle = < XlLineStyle(边线类型)>

XlLineStyle(边线类型): xlLineStyleNone ?无样式 xlContinuous ?单线 xlDash ?破折号线(间隔线) xlDashDot ?破折号 点线 xlDashDotDot ?破折号 点 点线 xlDot ?点线 xlDouble ?双横线 xlSlantDashDot ?斜点线 2. 设置边线的宽度

excel宏教程

Excel宏教程一、选中单个单元格Range(““).Select例:Range(\?选中“C9”单元格二、选中多个单元格Range(“:[,……]”).Select例:Range(“A1:B2”).Select?选中“A1”
推荐度:
点击下载文档文档为doc格式
7stbb1pjgn5dq8n1sb8p
领取福利

微信扫码领取福利

微信扫码分享