excel宏的使用

上传人:第*** 文档编号:34591637 上传时间:2018-02-26 格式:DOC 页数:16 大小:244KB
返回 下载 相关 举报
excel宏的使用_第1页
第1页 / 共16页
excel宏的使用_第2页
第2页 / 共16页
excel宏的使用_第3页
第3页 / 共16页
excel宏的使用_第4页
第4页 / 共16页
excel宏的使用_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《excel宏的使用》由会员分享,可在线阅读,更多相关《excel宏的使用(16页珍藏版)》请在金锄头文库上搜索。

1、EXCEL宏的使用 一、 选中单个单元格 Range(“).Select 例:Range(C9).Select 选中“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中的所有单元格 Row

2、s(:).Select 选中整行 Columns(:).Select 选中整列 例:Rows(“2:2”). Select 选中第 2行 Rows(“2:5”). Select 选中 2到 5行 Columns(A:A).Select 选中 A列 Columns(E:B).Select 选中 E到 B列 三、 设置活动单元格 Range().Activate 注:设置活动单元格与选中单元格类似,不同之处就是后者在选中指定的单元格之前会将在此前已被选中的单元格取消掉。前者在设置之前不会取消已选中的单元格,如果此时操作的单元格不是被选中的单元格,这时他实现的功能与选一个单元格相同。 四、 给活动的

3、单元格赋值 ActiveCell.FormulaR1C1 = 例:Range(A1).Select ActiveCell.FormulaR1C1 = Name Range(B1).Select ActiveCell.FormulaR1C1 = Age Range(A2:B3).Select Range(A2).Activate ActiveCell.FormulaR1C1 = BUG Range(B2).Activate ActiveCell.FormulaR1C1 = 12 Range(A3).Activate ActiveCell.FormulaR1C1 = Archer Range(B3

4、).Activate ActiveCell.FormulaR1C1 = 37 五、 得到指定单元格中的值 Range().Text 六、 插入单元格 Selection.Insert Shift:= Selection.EntireRow.Insert Selection.EntireColumn.Insert 例:Selection.Insert Shift:=xlToRight 在当前选中单元格的位置插入单元格并将当前选中的单元格向右移动 Selection.Insert Shift:=xlDown 在当前选中单元格的位置插入单元格并将当前选中的单元格向下移动 Selection.Enti

5、reRow.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 = 下划线 XlUnderlineSt

6、yle(下划线样式): xlUnderlineStyleDouble 双下划线 xlUnderlineStyleDoubleAccounting 会计用双下划线(如果当前单元格中的数据是数字时则下划线的宽度是当前单元格的宽度) xlUnderlineStyleNone 没有下划线 xlUnderlineStyleSingle 单下划线 xlUnderlineStyleSingleAccounting 会计用单下划线(如果当前单元格中的数据是数字时则下划线的宽度是当前单元格的宽度) 3. 设置字体的颜色 Selection.Font.ColorIndex = Selection.Font.Col

7、or = 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

8、(边线): xlEdgeLeft 单元格左边线 xlEdgeTop 单元格上边线 xlEdgeRight 单元格右边线 xlEdgeBottom 单元格下边线 xlDiagonalDown 单元格左上右下斜线 xlDiagonalUp 单元格左上右下斜线 xlInsideVertical 多个单元格内垂直线 xlInsideHorizontal 多个单元格内水平线 1. 设置边线的类型 Selection.Borders().LineStyle = XlLineStyle(边线类型): xlLineStyleNone 无样式 xlContinuous 单线 xlDash 破折号线(间隔线) x

9、lDashDot 破折号 点线 xlDashDotDot 破折号 点 点线 xlDot 点线 xlDouble 双横线 xlSlantDashDot 斜点线 2. 设置边线的宽度 Selection.Borders().Weight = XlBorderWeight(宽度值): xlHairline 极细 xlThin 细 xlMedium 中等 xlThick 粗 3. 设置边线的颜色 Selection.Borders(xlEdgeLeft).ColorIndex = Selection.Borders(xlEdgeLeft).Color = 十、 删除选中的单元格 Selection.D

10、elete Selection.EntireRow.Delete Selection.EntireColumn.Delete 例:Selection.Delete Shift:=xlToLeft 删除选中的单元格,并将已删除单元格所在位置右面的单元格向左移动 Selection.Delete Shift:=xlUp 删除选中的单元格,并将已删除单元格所在位置下面的单元格向上移动 Selection.EntireRow.Delete 删除选中单元格所在的行 Selection.EntireColumn.Delete 删除选中单元格所在的列 十一、设置单元格背景色及图案 1. 背景色 Select

11、ion.Interior.ColorIndex = Selection.Interior.Color = 2. 图案样式 Selection.Interior.Pattern = Constants(图案样式): xlSolid 实心 xlGray75 75% 灰色 xlGray50 50% 灰色 xlGray25 25% 灰色 xlGray16 12.5% 灰色 xlGray8 6.25% 灰色 xlHorizontal 水平 条纹 xlVertical 垂直 条纹 xlDown 逆对角线 条纹 xlUp 对角线 条纹 xlChecker 对角线 剖面线 xlSemiGray75 粗 对角线

12、 剖面线 xlLightHorizontal 细 水平 条纹 xlLightVertical 细 垂直 条纹 xlLightDown 细 逆对角线 条纹 xlLightUp 细 对角线 条纹 xlGrid 细 水平 剖面线 xlCrissCross 细 对角线 剖面线 3. 图案颜色 Selection.Interior.PatternColorIndex = Selection.Interior.PatternColor = 十二、返回工作表中的行数 Sheet1.UsedRange.Rows.Count 返回从最小已输入内容的行号到最大已输入内容的行号之间的行数 Sheet1.UsedRa

13、nge.Rows(Sheet1.UsedRange.Rows.Count).Row 最大已输入内容的行号 十三、得到当前 EXCEL的文件名 ThisWorkbook.Path 文件路径 ThisWorkbook.Name 文件名 ThisWorkbook.FullName 全路径 十四、批注的操作 1. 添加批注 AddComment(Content) 例:Range(A1).AddComment (Writes the content in here!) 2. 修改批注内容 Comment.Text 例:Range(B1).Comment.Text Text:= Writes the co

14、ntent in here! 3. 显示/隐藏批注 Comment.Visible = 4. 删除批注 ClearComments 例:Selection.Range(B1).ClearComments 5. 选中批注 Comment.Shape.Select True 例:Range(D8).Comment.Shape.Select True 6. 改变批注大小和位置 Selection.ShapeRange.ScaleWidth , msoFalse, Selection.ShapeRange.ScaleHeight , msoFalse, 例:Selection.ShapeRange.S

15、caleWidth 1.5, msoFalse, msoScaleFromTopLeft 每次增加 5%的宽度 Selection.ShapeRange.ScaleHeight 0.6, msoFalse, msoScaleFromTopLeft 每次减少 6%的宽度 Selection.ShapeRange.Left = Selection.ShapeRange.Top = Selection.ShapeRange.Width = Selection.ShapeRange.Height = 十五、剪切、复制、粘贴 Selection.Cut 剪切 Selection.Copy 复制 ActiveSheet.Paste 粘

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号