与给定范围地址的同一行中查找字符串值
我有一个搜索,可以通过有效的特定标头标识一个范围地址。
我正在处理的功能需要在同一行中搜索另一个标头字符串并返回单元格地址。
由于某种原因,查找函数不会在文件中使用标头的地址填充范围变量。
我尝试调整查找功能中的参数,但我没有任何运气来解决这个问题。
事先感谢您的帮助!
Private Sub FindAllHeadersInRow(dataFile As String, rng As String, headerName As String)
MsgBox "Finding all headers in the selected row"
'search left in the given row to find other header to copy data from under
Dim HeaderColFoundRng As Range
Dim dataWB As Workbook
Set dataWB = Workbooks.Open(dataFile)
Set HeaderColFoundRng = dataWB.Sheets("Sheet1").Range(rng).Find(What:=headerName, LookIn:=xlValues, _
LookAt:=xlWhole, SearchDirection:=xlPrevious) 'or xlNext
'needs to set each value address to a range that will be sent out
MsgBox HeaderColFoundRng.Address '<<< repeated variable not set error!
End Sub
Sub testSub2()
Dim FileToOpen As String
FileToOpen = Application.GetOpenFilename(Title:="Select Data file")
Call FindAllHeadersInRow(FileToOpen, "A68:AZ68", "Transaction Date") 'Header needed is located in T68
End Sub
I have a search that Identifies a range address with a specific header that works.
The function I am working on needs to search in the same row for another header string and return the cell address.
For some reason the find function does not populate the range variable with the address of the header in the file.
I have tried adjusting parameters in the find function but I am not having any luck figuring this out.
Thanks in advance for your help!
Private Sub FindAllHeadersInRow(dataFile As String, rng As String, headerName As String)
MsgBox "Finding all headers in the selected row"
'search left in the given row to find other header to copy data from under
Dim HeaderColFoundRng As Range
Dim dataWB As Workbook
Set dataWB = Workbooks.Open(dataFile)
Set HeaderColFoundRng = dataWB.Sheets("Sheet1").Range(rng).Find(What:=headerName, LookIn:=xlValues, _
LookAt:=xlWhole, SearchDirection:=xlPrevious) 'or xlNext
'needs to set each value address to a range that will be sent out
MsgBox HeaderColFoundRng.Address '<<< repeated variable not set error!
End Sub
Sub testSub2()
Dim FileToOpen As String
FileToOpen = Application.GetOpenFilename(Title:="Select Data file")
Call FindAllHeadersInRow(FileToOpen, "A68:AZ68", "Transaction Date") 'Header needed is located in T68
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论