Hi all,
I am writing a VBA code to find a string from a workbook and return the number from the cell below it.
The problem is that my workbook, worksheet names and the string to find are all variables and i can't open all the workbooks while running the code since I have too many workbooks here.
How do I define my search range? Lets assume all my workbooks are in C:\Folder\
I am writing a VBA code to find a string from a workbook and return the number from the cell below it.
The problem is that my workbook, worksheet names and the string to find are all variables and i can't open all the workbooks while running the code since I have too many workbooks here.
How do I define my search range? Lets assume all my workbooks are in C:\Folder\
Code:
Dim rngSearch As Range, rngFound As Range
Set rngSearch = Workbooks(bookname).Worksheets(sheetname).Range("B:M")
Set rngFound = rngSearch.Find(What:=mystring, LookIn:=xlValues, LookAt:=xlPart)
If rngFound Is Nothing Then
MsgBox "Not found"
Else
n = Workbooks(bookname).Worksheets(sheetname).Cells(rngFound.Row + 1, rngFound.Column)
End If