如上图,查找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函数的更多相关文章

  1. 【WEB小工具】jQuery函数

    jQuery-API帮助文档:Click here jQuery简介 jQuery是JavaScript框架,jQuery也是JavaScript代码.使用jQuery要比直接使用JavaScript ...

  2. 哪些优秀的 Windows 小工具,类似 clover 或 everything

    有哪些优秀的 Windows 小工具,类似 clover 或 everything? 目前已知的有everything, listary, total commander, clover, dexpo ...

  3. c#做的查找文件夹内内容的小工具

    第一次写博客有点激动啊QAQ 来新单位,一直没活干,公司代码控制器太多,其中有很多文件夹,每次找一个控制器都老找不到,我又不愿意用VS的全局搜索,想着没事就做了个查找控制器的小工具.代码如下: 先添加 ...

  4. 文件查找工具Everything小工具的使用

    Everything 小工具的使用: 首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用ever ...

  5. 2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,0 ...

  6. 2014年Windows平台软件推荐:神器小工具(骨灰级

    原文  http://www.wtoutiao.com/a/120621.html 底层工具 “If you know how to use Process Monitor competently, ...

  7. Windows平台软件推荐:神器小工具(骨灰级)

    底层工具 "If you know how to use Process Monitor competently, people of both sexes will immediately ...

  8. 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/ ...

  9. 网页抓取小工具(IE法)

    网页抓取小工具(IE法)—— 吴姐 http://club.excelhome.net/thread-1095707-1-1.html 用IE提取网页资料的好处在于:所见即所得,网页上能看到的信息一般 ...

随机推荐

  1. 【linux高级程序设计】(第十一章)System V进程间通信 4

    共享内存 共享内存主要用于实现进程间大量数据传输. 共享内存的数据结构定义: 系统对共享内存的限制: 共享内存与管道的对比: 可以看到,共享内存的优势: 1.共享内存只需复制2次,而管道需要4次 2. ...

  2. 考勤的lua脚本

    ngx.header.content_type = "text/plain;charset=utf-8" local cjson = require "cjson&quo ...

  3. PSR-1 基础编码规范

    本篇规范制定了代码基本元素的相关标准, 以确保共享的PHP代码间具有较高程度的技术互通性. 关键词 “必须”("MUST").“一定不可/一定不能”("MUST NOT& ...

  4. J.U.C并发框架源码阅读(五)Semaphore

    基于版本jdk1.7.0_80 java.util.concurrent.Semaphore 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is sub ...

  5. thinkphp函数学习(2)——microtime, memory_get_usage, dirname, strtolower, is_file

    1. microtime() 返回  微秒 秒  这种格式的内容 例子 <?php echo(microtime()); ?> 输出: 0.25139300 1138197510 // 前 ...

  6. ZOJ 3937 More Health Points (2016 浙江省赛 B题,可持久维护凸壳)

    题目链接  2016 ZJCPC Problem B 题意  CF 660F的树上版本. 其他做的方法都差不多,关键是把凸壳放到树上. 每次确定扔掉几个元素的时候直接$O(1)$修改(先不清楚这个位置 ...

  7. springboot引入thymeleaf

    springboot引入thymeleaf 1.Thymeleaf使用 @ConfigurationProperties(prefix = "spring.thymeleaf") ...

  8. my-git-wiki-doing

    github项目quick setup git初始化 git init git添加remote git remote add origin YOURS_REMOTE_URL git修改remote的u ...

  9. hdu 1425 Happy 2004

    题目链接 hdu 1425 Happy 2004 题解 题目大意: 求 \[\sum_{d|2004^{x}}d\ mod\ 29\] 记为\(s(2004^x)\) \(sum(2004^{x})= ...

  10. ARC 098 D - Xor Sum 2

    Problem Statement There is an integer sequence A of length N. Find the number of the pairs of intege ...