使用VBA宏搜索excel行中字符串的完全匹配 [英] Search for exact match of string in excel row using VBA Macro
问题描述
如何在Excel中的一行中搜索字符串?我有一个long类型变量中的行索引。
Dim rowIndex As Long
rowIndex = // some value在这里使用一些代码。
现在我需要检查一行中是否存在特定的值,whoose index是rowIndex。 p>
如果有匹配,我需要获取第一个匹配单元格的列索引。
我已尝试使用匹配函数,但我不知道如何传递rowIndex变量代替单元格范围。
Dim colIndex As Long
colIndex = Application.Match(colName,Range(B< my rowIndex here> ;: Z< my rowIndex here>),0)
尝试这样:
Sub GetColumns()
Dim lnRow As Long,lnCol As Long
lnRow = 3'用于测试
lnCol = Sheet1.Cells(lnRow,1 ).EntireRow.Find(What:=sds,LookIn:= xlValues,LookAt:= xlPart,SearchOrder:= xlByColumns,SearchDirection:= xlNext,MatchCase:= False).Column
End Sub
可能最好不要将colIndex和rowIndex用作变量Excel对象库中已经提到了可用的名称。
How do I search for a string in one particular row in excel? the I have the row index in a long type variable.
Dim rowIndex As Long
rowIndex = // some value being set here using some code.
Now I need to check if a particular value exists in the row, whoose index is rowIndex.
If there is match, I need to get the column Index of the first matching cell.
I have tried using Match function, but I dont know how to pass the rowIndex variable in place of the cell range.
Dim colIndex As Long
colIndex = Application.Match(colName, Range("B <my rowIndex here>: Z <my rowIndex here>"), 0)
Try this:
Sub GetColumns()
Dim lnRow As Long, lnCol As Long
lnRow = 3 'For testing
lnCol = Sheet1.Cells(lnRow, 1).EntireRow.Find(What:="sds", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Column
End Sub
Probably best not to use colIndex and rowIndex as variable names as they are already mentioned in the Excel Object Library.
这篇关于使用VBA宏搜索excel行中字符串的完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!