如何在 Excel 的某一特定行中搜索字符串?我有一个长类型变量的行索引。
Dim rowIndex As Long
rowIndex = // some value being set here using some code.
现在我需要检查该行中是否存在特定值,其索引为 rowIndex。
如果存在匹配,我需要获取第一个匹配单元格的列索引。
我尝试过使用 Match 函数,但我不知道如何传递 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 'For testing
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 对象库中提到过。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)