Murray Brown
asked on
VB.net Excel Add-in Find values on sheet and don't go past the end of the sheet
Hi
I am using the following VB.net code in my Excel Add-in to find all instances of a word on a spreadsheet.
The loop doesn't end at the end of the sheet but rather just carries in. What extra code can I include
to not go past the end of the sheet?
I am using the following VB.net code in my Excel Add-in to find all instances of a word on a spreadsheet.
The loop doesn't end at the end of the sheet but rather just carries in. What extra code can I include
to not go past the end of the sheet?
Dim blnFindError As Boolean = False
oFindWhat = "Total"
strSourceRange = oSourceWorkBook.Sheets(oSourceSheet).Cells.Address
Do Until blnFindError = True
Try
oFindAddress = oSourceWorkBook.Sheets(oSourceSheet).Range(strSourceRange).Find(
What:=oFindWhat, After:=oSourceWorkBook.Sheets(oSourceSheet).Range(oFindAfterAddress),
LookIn:=Excel.XlFindLookIn.xlValues, LookAt:=Excel.XlLookAt.xlPart, SearchOrder:=oSearchOrder,
SearchDirection:=Excel.XlSearchDirection.xlNext).Address
Catch ex As Exception
blnFindError = True
End Try
oFindAfterAddress = oFindAddress
Loop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.