网优257个Excel宏常用语句 下载本文

175、自动筛选全部显示指定列 ........................................................................................... 50 176、自动筛选第2列值为A的行 ...................................................................................... 50 177、取消自动筛选() ............................................................................................................ 50 178、全部显示指定表的自动筛选 ....................................................................................... 50 179、强行合并单元 ............................................................................................................... 50 180、设置单元区域格式 ....................................................................................................... 50 181、在所有工作表的A1单元返回顺序号 ........................................................................ 51 182、根据A1单元内容返回C1数值 .................................................................................. 51 183、根据A1内容选择执行宏 ............................................................................................ 51 184、删除A列空行 .............................................................................................................. 51 185、在A列产生不重复随机数 .......................................................................................... 52 186、将A列数据随机排列到F列 ....................................................................................... 52 187、取消选定区域的公式只保留值(假空转真空) ............................................................ 52 188、处理导入的显示为科学计数法样式的身份证号 ....................................................... 53 189、返回指定单元的行高和列宽 ....................................................................................... 53 190、指定行高和列宽 ........................................................................................................... 53 191、指定单元的行高和列宽与A1单元相同 .................................................................... 53 191、填公式........................................................................................................................... 53 192、建立当前工作表的副本为001表 ............................................................................... 54 193、在第一个表前插入多工作表 ....................................................................................... 54 194、清除A列再插入序号 .................................................................................................. 54 195、反方向文本(自定义函数) ............................................................................................ 54 196、指定选择单元区域弹出消息 ....................................................................................... 54 197、将B列数据添加超链接到K列 .................................................................................. 55 198、删除B列数据的超链接 .............................................................................................. 55 199、分离临时表A列数据的文本和超链接并整理到数据库表 ....................................... 55 200、分离临时表A列数据的文本和超链接并会同其他数据整理到数据库表 ............... 55 201、返回A列最后一个非空单元行号 .............................................................................. 56 202、返回表中第一个非空单元地址(行搜索) .................................................................... 56 203、返回表中各非空单元区域地址(行搜索) .................................................................... 56 204、返回第一个数值行号 ................................................................................................... 56 205、返回第1行最右边非空单元的列号 ........................................................................... 57 206、返回连续数值单元的数量 ........................................................................................... 57 207、统计指定范围和内容的单元数量 ............................................................................... 57 208、统计不同颜色的数字的和(自定义函数) ............................................................... 57 209、返回非空单元数量 ....................................................................................................... 57 210、返回A列非空单元数量 .............................................................................................. 58 211、返回圆周率π ............................................................................................................... 58 212、定义指定单元内容为页眉/页脚 ................................................................................. 58 213、提示并全部清除当前选择区域 ................................................................................... 58 214、全部清除当前选择区域 ............................................................................................... 58 215、清除指定区域数值 ....................................................................................................... 58 216、对指定工作表执行取消隐藏》打印》隐藏工作表 ................................................... 59 217、打开文件时执行指定宏(工作簿代码) ........................................................................ 59

218、关闭文件时执行指定宏(工作簿代码) ........................................................................ 59 219、弹出提示A1单元内容 ................................................................................................ 59 220、延时15秒执行重排窗口宏 ......................................................................................... 59 221、撤消工作表保护并取消密码 ....................................................................................... 60 222、重算指定表 ................................................................................................................... 60 223、将第5行移到窗口的最上面 ....................................................................................... 60 224、对第一张工作表的指定区域进行排序 ....................................................................... 60 225、显示指定工作表的打印预览 ....................................................................................... 60 226、用单元格A1的内容作为文件名另存当前工作簿..................................................... 60 227、[禁用/启用]保存和另存的代码 ................................................................................... 60 228、在A和B列返回当前选区的名称和公式 .................................................................. 61 229、朗读朗读A列,按ESC键中止...................................................................................... 61 230、朗读固定语句,请按ESC键终止 ............................................................................... 61 231、在M和N列的14行以下选择单元时显示调用日历控件(工作表代码) ........... 62 232、添加自定义序列 ........................................................................................................... 62 233、弹出打印对话框 ........................................................................................................... 62 234、返回总页码 ................................................................................................................... 62 235、合并各工作表内容 ....................................................................................................... 63 236、合并指定目录中所有文件中相同格式工作表的数据 ............................................... 64 237、隐藏指定工作表的指定列 ........................................................................................... 64 238、把a列不重复值取到e列 ........................................................................................... 65 239、当前选区的行列数 ....................................................................................................... 65 240、单元格录入1位字符就跳转(工作表代码) ................................................................ 65 241、当指定日期(每月10日)打开文件执行宏 ............................................................. 65 242、提示并清空单元区域 ................................................................................................... 66 243、返回光标所在行号 ....................................................................................................... 66 244、按照当前行A列的图片名称插入图片到H列 .......................................................... 66 245、当前行下插入1行 ....................................................................................................... 66 246、取消指定行或列的隐藏 ............................................................................................... 67 247、复制单元格所在行 ....................................................................................................... 67 248、复制单元格所在列 ....................................................................................................... 67 249、新建一个工作表 ........................................................................................................... 67 250、新建一个工作簿 ........................................................................................................... 67 251、选择多表为工作组 ....................................................................................................... 67 252、在当前工作组各表中分别执行指定宏 ....................................................................... 68 253、复制当前工作簿的报表到临时工作簿 ....................................................................... 69 254、删除指定文件 ............................................................................................................... 70 255、合并A1至C1的内容写到D15单元的批注中 .......................................................... 70 256、自动重算....................................................................................................................... 70 257、手动重算....................................................................................................................... 70

1、打开全部隐藏工作表

Sub 打开全部隐藏工作表() Dim i As Integer

For i = 1 To Sheets.Count Sheets(i).Visible = True Next i End Sub

2、循环宏

Sub 循环()

AAA = Range(\ Dim i As Long

Dim times As Long times = AAA

'times代表循环次数,执行前把times赋值即可(不可小于1,不可大于2147483647) For i = 1 To times Call 过滤一行

If Range(\完成标志\完成\ Exit For

'如果名为'完成标志'的命名单元的值等于'完成',则退出循环,如果一开始就等于'完成',则只执行一次循环就退出

'If Sheets(\传送参数\完成\ '如果某列出现\完成\内容则退出循环 Next i End Sub

3、录制宏时调用“停止录制”工具栏

Sub 录制宏时调用停止录制工具栏()

Application.CommandBars(\End Sub

4、高级筛选5列不重复数据至指定表

Sub 高级筛选5列不重复数据至Sheet2()

Sheets(\清除Sheet2的A:D列

Range(\ \

Sheet2.Columns(\Header:=xlGuess, _

OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _

:=xlPinYin End Sub

5、双击单元执行宏(工作表代码)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Range(\关闭\ Exit Sub

Select Case Target.Address Case \ Call 宏1 Cancel = True Case \ Call 宏2 Cancel = True Case \ Call 宏3 Cancel = True Case \ Call 宏4 Cancel = True End Select End Sub

6、双击指定区域单元执行宏(工作表代码)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Range(\关闭\

If Not Application.Intersect(Target, Range(\打开隐藏表

End Sub

7、进入单元执行宏(工作表代码)

Private Sub Worksheet_SelectionChange(ByVal Target As Range) '以单元格进入代替按钮对象调用宏

If Range(\关闭\ Select Case Target.Address

Case \单元地址(Target.Address),或命名单元名字(Target.Name) Call 宏1 Case \ Call 宏2 Case \