【VBA研究】工作表自己主动筛选模式检測
作者:iamlaosong
用VBA程序处理Excel数据文件。用户的数据文件有时处于自己主动筛选模式,往往导致数据处理不对。为此,须要检測工作表是否处于该模式,假设是,则去掉自己主动筛选。语句例如以下:
If ActiveSheet.AutoFilterMode = True Then Selection.AutoFilter
这个语句一般仅仅用于去掉自己主动筛选,尽管Selection.AutoFilter也能够加上自己主动筛选,但筛选位置却可能在当前单元格处,所以要注意。加自己主动筛选前,现将单元格定位到字段标题处。然后用例如以下语句:
If ActiveSheet.AutoFilterMode = False Then Selection.AutoFilter
假设检測其他非活跃的工作表,能够用以下语句:
If Worksheets("sheet1").AutoFilterMode = True Then
Worksheets("sheet1").Range("A1").AutoFilter
| Excel Developer Reference |
Filters a list using the AutoFilter.
Syntax
expression.AutoFilter(Field, Criteria1, Operator, Criteria2, VisibleDropDown)
expression An expression that returns a Range object.
Parameters
| Name | Required/Optional | Data Type | Description |
|---|---|---|---|
| Field | Optional | Variant | The integer offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field one). |
| Criteria1 | Optional | Variant |
The criteria (a string; for example, "101"). Use "=" to find blank fields, or use "<>" to find nonblank fields. If this argument is omitted, the criteria is All. If Operator is xlTop10Items, Criteria1 specifies the number of items (for example, "10"). |
| Operator | Optional | XlAutoFilterOperator | One of the constants of XlAutoFilterOperator specifying the type of filter. |
| Criteria2 | Optional | Variant |
The second criteria (a string). Used with Criteria1 and Operator to construct compound criteria. |
| VisibleDropDown | Optional | Variant |
True to display the AutoFilter drop-down arrow for the filtered field. False to hide the AutoFilter drop-down arrow for the filtered field. True by default. |
Return Value
Variant
Remarks
If you omit all the arguments, this method simply toggles the display of the AutoFilter drop-down arrows in the specified range.
Example
This example filters a list starting in cell A1 on Sheet1 to display only the entries in which field one is equal to the string "Otis". The drop-down arrow for field one will be hidden.
| Visual Basic for Applications |
|---|
|
【VBA研究】工作表自己主动筛选模式检測的更多相关文章
- VBA验证工作表是否存在
使用VBA验证工作表是否存在 ============================================================= 代码区域 ================== ...
- 使用VBA从工作表中读图片,以及给工作表中写文件
因为工作的原因,需要用到VBA,碰到读图片和写图片: Sub Macro01() '从工作表中保存图片 Application.ScreenUpdating = False Dim pth, shp, ...
- Excel VBA ——批量工作表重命名
虽然平常在用excel 2010重命名工作表的时候,一般可能会用"双击工作表"的方法来重名,但是遇到大批量重名的时候就很麻烦. 我的方法,先建一张新表,然后在第一列写好要命名的表名 ...
- [VBA]获得工作表名称
sub 获得工作表名称() Dim i As Integer For i = 1 To Worksheets.Count Cells(i, 2) = Worksheets(i).Name Next E ...
- Excel VBA 判断工作表是否为空或被使用过(比如设置过框线)
IsEmpty 函数 返回 Boolean 值,指出变量是否已经初始化. [语法] IsEmpty(expression) 必要的 expression 参数是一个 Variant,包含一个数值或字符 ...
- excel-合并多个Excel文件--VBA合并当前目录下所有Excel工作簿中的所有工作表
在网上找EXCEL多文件合并的方法,思路: 一.Linux 或者window+cmder,直接用命令行cat合并EXCEL文件,但是,需要安装辅助东西才能直接处理(也许也不可以,但是,可以用文件格式转 ...
- 在VBA中调用工作表函数
虽然VBA几乎可以完成所有工作表函数的功能,但是有时候在无法打开思路的时候,适当调用一些工作表函数也未尝不可,在VBA中调用工作表函数需要用到 WorksheetFunction对象,例如: Work ...
- Excel 2010 如何将筛选后的数据复制粘贴到另一个工作表筛选后的表格里
如果你是指自动筛选后,把筛选数据复制/粘贴到另外一个工作表中,不妨试试试 第一步选中筛选后的数据区域:第二步执行菜单命令“编辑/定位/定位条件/可见单元格”,确定:第三步单击复制按钮或者Ctrl+C或 ...
- 【VBA】获取当前工作表的用户名
如何使用VBA获取当前工作表的用户名呢?请看如下代码: Sub 获取当前工作表的用户名() MsgBox "当前工作表的用户名为:" & Application.UserN ...
随机推荐
- Hibernate的入门使用
数据在各个层次之间流转,在流转过程中会发生数据类型转换等一系列的交互问题.java与html的交互解决方案是struts2提供的OGNL(对象导航图语言),而java与数据库之间的技术解决方案是ORM ...
- WPF动画 - Loading加载动画
存在问题: 最近接手公司一个比较成熟的产品项目开发(WPF桌面端),其中,在登陆系统加载时,60张图片切换,实现loading闪烁加载,快有密集恐惧症了!!! 代码如下: private void L ...
- 判断Exe(DLL)和符号文件是否匹配---验证模块和符号文件是否匹配的工具和方法
当我们进行程序调试时,有时调试器会直接告诉你符号文件不对,或则显示出的调用栈不对,当你怀疑符号文件不匹配时,如何确定呢? 如果是用windbg调试,请用 !chksym 模块名比如,匹配的时候 不匹 ...
- _bbox_pred函数
fast中的_bbox_pred函数和faster中的bbox_transform_inv是一样的,是将框进行4个坐标变换得到新的框坐标.fast中是将selective search生成的框坐标进行 ...
- vue之packages.json添加注释的正确写法
(1)问题描述 使用vue脚手架vue-cli搭建好项目架构后,在packages.json文件里,加入注释(如下所示).接下来,运行npm run dev命令后出现报错 (2)问题解析 ①记得jso ...
- error while loading shared libraries: libclntsh.so.11.1
解决这个问题有两种方法 1.在当前用户下,添加链接库所在路径 LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_ ...
- 编译压缩代码 MFCompress-src-1.01 :对‘***’未定义的引用
提示 MFCompressD.o:在函数‘main’中:MFCompressD.c:(.text.startup+0x34a): 警告: the use of `tempnam' is dangero ...
- 题解 P1967 货车运输
题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物,司机们想知道每辆车在不超过车辆限重的情况下,最多能 ...
- HDU - 2058 The sum problem(思路题)
题目: Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the ...
- 笔试算法题(13):反转链表 & 左旋转字符串
出题:反转链表(递归和非递归解法): 分析:有递归跟非递归实现,注意对原始链表头节点的处理,因为其他节点都指向下一个节点,其需要指向NULL: 解题: struct Node { int v; Nod ...