Search worksheet and get value next to the cell found.

abenitez77

Board Regular
Joined
Dec 30, 2004
Messages
149
I am searching for a string ("SUPPLIER:") in my spreadsheet. If found I want to return the location i.e. B6. Then I want to get the value of the cell next to B6 (the found cell) and put it in a string variable. i.e. var1 = B7. How can I modify my search code below to do that?


Set rSheet = ActiveSheet.UsedRange

'###########################################
currentSheet = ActiveSheet.Index
sheetCount = ActiveWorkbook.Sheets.Count

For counter = 1 To sheetCount

Sheets(counter).Activate

mySearch = "SUPPLIER:"
With Worksheets(counter).UsedRange
Set iSheet2 = .Find(What:=mySearch, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchFormat:=False)
If Not iSheet2 Is Nothing Then
'found it.
xFilePath = ActiveWorkbook.FullName
xFileName = ActiveWorkbook.Name
foundcell = iSheet2.Address
'ActiveCell.Value
strFound = mySearch
Exit For
End If


End With

Next Counter
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Put this after your 'foundCell' statement.
Code:
myVal = iSheet2.Offset(0, 1).Value
 
Upvote 0

Forum statistics

Threads
1,216,069
Messages
6,128,600
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top