热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ExcelVBA比较A列和B列-ExcelVBAComparecolumnAtoColumnB

Imtryingtorunthiscodehere:我试着运行这个代码:PrivateSubCommandButton1_Click()DimRow_AAsIn

I'm trying to run this code here:

我试着运行这个代码:

Private Sub CommandButton1_Click()
    Dim Row_A As Integer, Row_B As Integer, Is_Copy As Boolean
    Is_Copy = False

    For Row_A = 1 To 850
        For Row_B = 1 To 10840
            Is_Copy = IsNumber(Search(Cells(Row_A, 1), Cells(Row_B, 2), 1))
            If Is_Copy Then Cells(Row_B, 2).Interior.Color = RGB(255, 0, 0)
            If Is_Copy Then Cells(Row_B, 3).Value = Is_Copy
            If Is_Copy Then Cells(Row_B, 4).Value = Row_A
            If Is_Copy Then Cells(Row_B, 5).Value = Row_B


            Is_Copy = False
        Next Row_B
    Next Row_A
End Sub

But i get a popup saying:

但是我得到一个弹出窗口说:

"Compile error: Sub or Function not defined"

“编译错误:未定义的子或函数”

It then highlights Line 1 and the Search in Line 7.

然后突出显示第1行和第7行中的搜索。

What do I need to do to fix this?

我需要做什么来解决这个问题?

The issue I am trying to fix: I have two UID lists normally I would just compare the two of them, but Column b has 3 extra chars on the end so im using search to check to see if Column b Contains Column A.

我要解决的问题是:我有两个UID列表,通常我只是比较它们两个,但是b列有3个额外的字符,所以我用搜索来检查b列是否包含A列。

4 个解决方案

#1


1  

Search is not a function in VBA. Unless you have a UDF with that name, the code will throw an error.

搜索不是VBA中的函数。除非您有一个UDF与该名称,否则代码将抛出一个错误。

#2


0  

I've been using this for that kind of function, found in a previous SO thread. It's not a VBS answer, but might be an easier way to accomplish your goal.

我在之前的SO线程中使用过这种函数。这不是VBS的答案,但可能是实现目标的更简单的方法。

=IF(ISNA(VLOOKUP(,,1,FALSE)),FALSE, TRUE)

-or-

或者,

=IF(ISNA(VLOOKUP(,,1,FALSE)),"FALSE", "File found in row "   & MATCH(,,0))

You could replace and with named ranged. That'd probably be the easiest.

您可以替换并使用命名的远程。那可能是最简单的了。

Just drag that formula all the way down the length of your I column in whatever column you want.

只要把这个公式拖到你想要的任何列中。

#3


0  

Replace

取代

Is_Copy = IsNumber(Search(Cells(Row_A, 1), Cells(Row_B, 2), 1))

with something like

与类似的

Is_Copy = InStr(Cells(Row_A, 1), Cells(Row_b, 2)) > 0

IsNumber and Search are not VBA methods, they are worksheet functions.

IsNumber和Search不是VBA方法,它们是工作表函数。

#4


0  

as pointed above search is not a vb method or function. the best way to compare in a excel will be using the VLOOKUP excel function which dont need to write any vba script also.

如上所述,搜索不是vb方法或函数。在excel中进行比较的最好方法是使用VLOOKUP excel函数,该函数不需要编写任何vba脚本。


推荐阅读
author-avatar
狂风
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有