如何在 Excel 工作表中找到确切的值 [英] How to find an exact value in an Excel sheet

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

问题描述

如何在 Excel 工作表中找到字符串值.我正在尝试 objRange.Find() 但这也给了我错误的地址.例如,我想要Object_paint"的地址,但它也给出了Object_paint_and_stk"的地址

How could I find a string value in an excel sheet. I am trying objRange.Find() but this give me the wrong address too. As example i want the address of 'Object_paint' but it gives also the address of 'Object_paint_and_stk'

我应该如何获得精确的值..?

How should i get only exact value..?

Set objWorksheet = objWorkbook.Worksheets(worksheet)
Set objRange = objWorksheet.Range("B2:B600")    
Set objFind = objRange.Find("object_paint")

If Not objFind Is Nothing Then
    searchValue = objFind.AddressLocal(False, False)
end if

推荐答案

First hit for

First hit for

excel range.find exact match site:microsoft.com

是:

Range.Find

找到了

看看类型:System.Object

LookAt Type: System.Object

Optional Object. Can be one of the following XlLookAt constants: xlWhole or xlPart.

并遵循 LookAt 链接,你看:

xlPart  Match against any part of the search text.
xlWhole Match against the whole of the search text.

顺便说一句:objTarget 是谁?

BTW: Who is objTarget?

更新:

您必须移植"(一些提示此处)您在对 VBScript 的评论中提到的 VBA 代码片段:

You have to 'port' (some hints here) the VBA code snippet you mention in your comment to VBScript:

Option Explicit

' Define Excel Consts unknown to VBScript
Const xlPart  = 2 
Const xlWhole = 1 

Dim oExcel : Set oExcel = CreateObject("Excel.Application")
Dim oWBook : Set oWBook = oExcel.Workbooks.Open("M:\lib\kurs0705\testdata\ut.xls")
Dim oRange : Set oRange = oWBook.Sheets("NewSheet").Range("A1:A11")
' translate named args to positional args
' expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte)
Dim oFnd1  : Set oFnd1  = oRange.Find("Title1", , , xlPart)
WScript.Echo TypeName(oFnd1), CStr(oFnd1)
Dim oFnd2  : Set oFnd2  = oRange.Find("Title1", , , xlWhole)
WScript.Echo TypeName(oFnd2), CStr(oFnd2)

oWBook.Close
oExcel.Quit

输出:

cscript excelfind.vbs
Range Title10
Range Title1

这篇关于如何在 Excel 工作表中找到确切的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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