Hi Somnath
I'm AnnaThomas and I'd be happy to help you with your question. In this Forum, we are Microsoft consumers just like yourself.
It looks like the problem is with the line:
CreatingSummaryReport = cell. Offset(0, 6). Value
The function is expected to return a value of type Long, but the cell object may not be found, and in that case, its Offset property will return an error. You should add error handling to ensure that the function returns a value only when the cell is found. You can use the On Error Resume Next statement to skip over any errors and return a value of 0 in case the cell is not found.
Here is an updated version of the function:
Function CreatingSummaryReport(Cellone As Range) As Long
Dim cell As Range Dim Rng As Range
On Error Resume Next
Set Rng = Sheets(1). Range("F:F"). Find(What:=Cellone.Value, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False)
If Rng Is Nothing Then CreatingSummaryReport = 0 Exit Function End If
Set cell = Rng.CurrentRegion.Find(What:="TOTAL", Lookat:=xlWhole)
If cell Is Nothing Then CreatingSummaryReport = 0 Exit Function End If
CreatingSummaryReport = cell. Offset(0, 6). Value
End Function
With these changes, the function will return 0 if either the Rng or cell objects are not found, and otherwise return the value of the Offset property.
I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.
Best Regards,
AnnaThomas
Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.