Custom Function To Read Data

mouse88

Board Regular
Joined
May 24, 2011
Messages
148
I have the following function:

Code:
Public Function FINDDATA(SearchString As String, FilePath As String, SearchRange As String, ColOffset As Integer, _
RowOffset As Integer) As Variant
Dim WkBook As Workbook
Dim ResultRange As Range
Set WkBook = Workbooks.Open(FilePath, True, True)
Set ResultRange = WkBook.Worksheets("Sheet1").Range(SearchRange).Find(SearchString)
If ResultRange Is Nothing Then
    FINDDATA = "#REF!"
Else
    Set FINDDATA = WkBook.Worksheets("Sheet1").Range.Find(SearchString).Offset(ColOffset, RowOffset).Value
End If
End Function

This stops on the line:
Set ResultRange = WkBook.Worksheets("Sheet1").Range(SearchRange).Find(SearchString)

It doesn't throw any errors just seems to exit the code and gives a #VALUE error.

Can anyone see anything obvious?

Thanks

Matt
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have tried this:

Code:
Public Sub FINDDATASUB()
Dim WkBook As Workbook
Dim ResultRange As Range
Set WkBook = Workbooks.Open("C:\Users\Matt\Desktop\01.06.11\Summary.xlsx")
Set ResultRange = WkBook.Worksheets("Sheet1").Range("A:A").Find("Test")
If ResultRange Is Nothing Then
 
Else
    MsgBox (WkBook.Worksheets("Sheet1").Range("A:A").Find("Test").Offset(0, 1).Value)
End If
End Sub

This works fine and it opens the workbook. The value in the cell for my firect function is exactly the same filepath so I cant see any reason why it wont open the workbook.

Heres the formula I was using with the first function:

=FINDDATA("Test", D3,"A:A", 0, 1)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

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