Return a Range from Function

R

RyanH

I am trying to return a range from a function and I am getting an error:
Application Definded of Object-Defined Error, any ideas why? I then want to
use the Col D portion of the Range that is returned in my msgbox. Is my code
correct for this?

Sub TEST()

Dim aryPartDes(0 To 25) As Variant
Dim aryPartQty(0 To 25) As Variant

If CheckBox1 = True Then
' TopDoor
aryPartDes(0) = PartInfo("EXT00011742")
aryPartQty(0) = tbxCabSizeWft + tbxCabSizeWins / 12

MsgBox aryPartDes(0).Cells(3).Value
End If
End Sub

Public Function PartInfo(PartNumber As String) As Range

Dim lngRow As Long

lngRow = WorksheetFunction.Match(PartNumber, Sheets("Parts
List").Range("A:A"), 0)
Error>> Set PartInfo = Sheets("Parts List").Range(Cells(lngRow, "A"),
Cells(lngRow, "D"))

End Function

End Sub
 
S

shg

Maybe ...

Code:
--------------------
Sub TEST()
Dim aryPartDes(0 To 25) As Range
Dim aryPartQty(0 To 25) As Variant

If ActiveSheet.CheckBox1 = True Then
' TopDoor
Set aryPartDes(0) = PartInfo("EXT00011742")
aryPartQty(0) = tbxCabSizeWft + tbxCabSizeWins / 12

MsgBox aryPartDes(0).Cells(3).Value
End If
End Sub

Public Function PartInfo(PartNumber As String) As Range
Dim lngRow As Long

With Sheets("Parts List")
lngRow = WorksheetFunction.Match(PartNumber, .Range("A:A"), 0)
Set PartInfo = .Range(.Cells(lngRow, "A"), .Cells(lngRow, "D"))
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top