如何使用Excel VBA代码在工作表的列中查找确切的文本字符串 [英] How to find the exact text string in a column of sheet using excel vba code

查看:191
本文介绍了如何使用Excel VBA代码在工作表的列中查找确切的文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Excel VBA查找与特定单元格值完全匹配的字符串.例如,如果我想在A列中搜索"userid"(仅整个字符串).我可以编写一些代码行,但是即使我在其中输入了一些字母,该程序也无法找到整个单词.匹配整个单词的字符串.代码如下:

How can I find the exact string matching to particular cell value using Excel VBA. For example if I want to search "userid"(whole string only) in column A. I am able to write some lines of code but the program is not able to find the whole word, even if I type some of the letters in the string matching the whole word. Code is as given below:

Private Sub CommandButton1_Click()
Dim Username As String, password As String
Dim FindRow1 As Range, FindRow2 As Range
Dim WB As Workbook

Username = "user"
password = "pass"
Set WB = ThisWorkbook

With WB.Sheets("Master_Data")
Set FindRow1 = .Range("A:A").Find(What:=Username, LookIn:=xlValues)
Set FindRow2 = .Range("B:B").Find(What:=password, LookIn:=xlValues)
End With
MsgBox FindRow1
MsgBox FindRow2

即使我将值分别传递为username ="user"和password ="pass",这在逻辑上也是错误的.在这里,我正在msgbox中以用户ID和密码获取输出.

Here I am getting output in msgbox as userid and password even if I pass the values as username = "user" and password = "pass" which is logically wrong.

推荐答案

使用

这篇关于如何使用Excel VBA代码在工作表的列中查找确切的文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆