VBA 按列查找小工具类似lookUp函数

如上图,查找A列的数据在D,F列是否存在,如果存在背景色变绿,如果不存在则A列的背景色变红。
直接贴上代码:
Private Sub CommandButton1_Click()
Call lookUpAToDF
End Sub
Public Sub lookUpAToDF()
Dim a, d, f As Long
'Count of non-empty data in colum A,D,F
a = Application.WorksheetFunction.CountA(Range("A:A"))
d = Application.WorksheetFunction.CountA(Range("D:D"))
f = Application.WorksheetFunction.CountA(Range("F:F"))
Dim ac, dc, fc As Integer
'loop the A
For ac = To a Step
Dim aTxt As String
' get column A value
aTxt = TrimSpace(Cells(ac, ).Text)
If aTxt = "" Then
Exit For
End If
' add flg var for switch selected aTxt
Dim flg As Boolean
flg = True
For dc = To d Step
Dim dTxt As String
dTxt = TrimSpace(Cells(dc, ).Text)
If aTxt = dTxt Then
flg = False
Exit For
End If
Next dc
'if column D selected result is empty then
'loop the colum F
If flg Then
For fc = To f Step
Dim fTxt As String
fTxt = TrimSpace(Cells(fc, ).Text)
If aTxt = fTxt Then
flg = False
Exit For
End If
Next fc
End If
If flg Then
Cells(ac, ).Interior.ColorIndex = 'red
Else
Cells(ac, ).Interior.ColorIndex = 'green
End If
Next ac
MsgBox "find completed!"
End Sub
Public Function TrimSpace(strItem As String) As String
Dim resultStr As String
resultStr = LTrim(strItem)
resultStr = RTrim(resultStr)
TrimSpace = resultStr
End Function
代码还没有优化,行数达到10000+的时候会有卡顿。
VBA 按列查找小工具类似lookUp函数的更多相关文章
- 【WEB小工具】jQuery函数
jQuery-API帮助文档:Click here jQuery简介 jQuery是JavaScript框架,jQuery也是JavaScript代码.使用jQuery要比直接使用JavaScript ...
- 哪些优秀的 Windows 小工具,类似 clover 或 everything
有哪些优秀的 Windows 小工具,类似 clover 或 everything? 目前已知的有everything, listary, total commander, clover, dexpo ...
- c#做的查找文件夹内内容的小工具
第一次写博客有点激动啊QAQ 来新单位,一直没活干,公司代码控制器太多,其中有很多文件夹,每次找一个控制器都老找不到,我又不愿意用VS的全局搜索,想着没事就做了个查找控制器的小工具.代码如下: 先添加 ...
- 文件查找工具Everything小工具的使用
Everything 小工具的使用: 首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用ever ...
- 2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,0 ...
- 2014年Windows平台软件推荐:神器小工具(骨灰级
原文 http://www.wtoutiao.com/a/120621.html 底层工具 “If you know how to use Process Monitor competently, ...
- Windows平台软件推荐:神器小工具(骨灰级)
底层工具 "If you know how to use Process Monitor competently, people of both sexes will immediately ...
- C#7.2——编写安全高效的C#代码 c# 中模拟一个模式匹配及匹配值抽取 走进 LINQ 的世界 移除Excel工作表密码保护小工具含C#源代码 腾讯QQ会员中心g_tk32算法【C#版】
C#7.2——编写安全高效的C#代码 2018-11-07 18:59 by 沉睡的木木夕, 123 阅读, 0 评论, 收藏, 编辑 原文地址:https://docs.microsoft.com/ ...
- 网页抓取小工具(IE法)
网页抓取小工具(IE法)—— 吴姐 http://club.excelhome.net/thread-1095707-1-1.html 用IE提取网页资料的好处在于:所见即所得,网页上能看到的信息一般 ...
随机推荐
- python--optparse
import optparse op = optparse.OptionParser() op.add_option("--s", dest="server") ...
- how to configure team on liunx(RHEL7.x/Centos7.x)
#install team sofeware yum install teamd -y #check team configuration nmcli con show #Next we create ...
- 使用bottle进行web开发(1):hello world
为什么使用bottle?因为简单,就一个py文件,和其他模块没有依赖,3000多行代码. http://www.bottlepy.org/docs/dev/ 既然开始学习,就安装它吧. pip3 in ...
- 同样的promise,调用方法不一样,执行顺序不一样
在测试两个不同的代码时发现的. 其实也理解,一个是新建一个空的promise,另一个是新建的promise马上执行,去分支resolve状态, 当然就空的在后. <script> //se ...
- Informix 启动 Fatal error in shared memory initialization解决方法
https://blog.csdn.net/cy309173854/article/details/54929735
- Ubuntu 16.04/CentOS 6.9安装Apache压力(并发)测试工具ab
说明: ab工具已经在Apache中包含,如果不想安装Apache,那么可以使用下面方法单独安装. 安装: Ubuntu: sudo apt-get install apache2-utils Cen ...
- Enum枚举类使用集合
1.使用扩展方法使用枚举值对于的Description属性值 public static class EnumExtenstion { public static string GetDescript ...
- 15 个 Docker 技巧和提示
CLI(Command Line Interface,命令行) 好的 docker ps 输出 将 docker ps 输出通过管道重定向到 less -S,避免折行: docker ps -a | ...
- python+ubuntu+selenium安装chrome和chromedriver
请确保selenium已经安装成功,没安装的可以pip install selenium 安装chrome 在终端输入 下载安装包 wget https://dl.google.com/linux/d ...
- jstl <fmt:formatDate>标签
<fmt:formatDate>标记用于在各种不同的方式来格式化日期 属性: <fmt:formatDate>标签具有以下属性: 属性 描述 必需 默认值 value 要显示的 ...