Hi Everyone,
I have almost 90 different workbooks and in each of them there are like 5-10 sheets. I basically have to search through Each of these sheets in each workbook to find a Value NEXT to a certain cell. e.g. If in a sheet, in a particular range it is written "Contract Value:" then i will get the value NEXT to this cell which of course will be the value of contract or value required.
The problem is while searching a certain range that contains the string "Contract" its NOT always getting it right due to the fact that somewhere it is written "Contract Value:" and somewhere else it might be "Contract Value: " (i.e. with spaces after "Value:") and sometimes it can be like "Contract Value:" (more spaces b/w Contract and value).
Here is my overall code but its NOT giving correct values where it deviates from the EXACT "Contract Value:" string.
Any help is appreciated.
I have almost 90 different workbooks and in each of them there are like 5-10 sheets. I basically have to search through Each of these sheets in each workbook to find a Value NEXT to a certain cell. e.g. If in a sheet, in a particular range it is written "Contract Value:" then i will get the value NEXT to this cell which of course will be the value of contract or value required.
The problem is while searching a certain range that contains the string "Contract" its NOT always getting it right due to the fact that somewhere it is written "Contract Value:" and somewhere else it might be "Contract Value: " (i.e. with spaces after "Value:") and sometimes it can be like "Contract Value:" (more spaces b/w Contract and value).
Here is my overall code but its NOT giving correct values where it deviates from the EXACT "Contract Value:" string.
Code:
For Each ws In wb.Worksheets
count = count + 1
On Error Resume Next
With ws
ws.Unprotect
Set valLoc1 = .Range("F30:F70").Find(What:="Gross Margin", LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows)
valNew1 = valLoc1.Offset(0, 1).Value
For Each rCell In Range("F5:F10")
If InStr(1, rCell.Value, "Contract Value:") Then
valNew2 = rCell.Offset(0, 1).Value
Else
End If
Next
newRng.Offset(count, 1).Value = wb.Name
newRng.Offset(count, 2).Value = ws.Name
newRng.Offset(count, 3).Value = valNew1
newRng.Offset(count, 4).Value = valNew2
End With
Next ws