如上图,查找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. python 向mysql插入数据

    生成随机内容用到的方法: substr是一个字符串函数,从第二个参数1,开始取字符,取到3 + floor(rand() * 75)结束 floor函数代表的是去尾法取整数. rand()函数代表的是 ...

  2. 解决:java.lang.ArrayIndexOutOfBoundsException: 160 at com.alibaba.fastjson.serializer.SerializeWriter.writeStringWithDoubleQuote(SerializeWriter.java:868)

    今天线上遇到一个问题,从hbase里读取出来的数据在转换json后输出时出现异常: java.lang.ArrayIndexOutOfBoundsException: 160 at com.aliba ...

  3. springBoot Ribbon Hystrix

    1.依赖包引入 <!-- 引入关于 hystrix的依赖 --> <dependency> <groupId>org.springframework.cloud&l ...

  4. python学习之-- 动态导入模块

    python 动态导入模块方法1: __import__ 说明: 1. 函数功能用于动态的导入模块,主要用于反射或者延迟加载模块. 2. __import__(module)相当于import mod ...

  5. (1)oracle安装、卸载、启动、关闭、登陆以及同时遇到的问题

    数据库概念 在oracle里数据库是一个静态的概念,数据库的资料保存在硬盘上,一个数据库可以有多个实例 数据库实例 数据库实例是一个动态的概念,它是进程+这个进程的内存块.就把它当成个指针吧,这个指针 ...

  6. [Python Cookbook] Pandas Groupby

    Groupby Count # Party’s Frequency of donations nyc.groupby(’Party’)[’contb receipt amt’].count() The ...

  7. [CP1804]最短路

    题目大意: 一个$n(n\le10^5)$个点的图,给定一个常数$c$,每对点$i,j$之间有权值为$(i\oplus j)\times c$的边.另有$m(m\le5\times10^5)$条指定权 ...

  8. Android kernel Crash后,定位出错点的方法

    转载:http://blog.csdn.net/wlwl0071986/article/details/11635749 1. 将/prebuild/gcc/linux-x86/arm/arm-lin ...

  9. cocurrent包semaphore信号量

    semaphore英[ˈseməfɔ:(r)]美[ˈsɛməˌfɔr, -ˌfor]n. 臂板信号系统,(铁道)臂板信号装置; Semaphore 用法 信号量主要有两种用途: 保护一个重要(代码)部 ...

  10. redis--AOF

    Redis 分别提供了 RDB 和 AOF 两种持久化机制: RDB 将数据库的快照( snapshot)以二进制的方式保存到磁盘中. 相当于MySQL binlog 的 raw模式 AOF 则以协议 ...