Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Return a Range from Function

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
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Return a Range from Function


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
--------------------


--
shg
------------------------------------------------------------------------
shg's Profile: http://www.thecodecage.com/forumz/member.php?userid=13
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=25569

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
function like INDIRECT to return a range? Wilba Excel Worksheet Functions 4 November 17th 07 04:42 AM
I would like a function to return a value that fits its range rpbsr Excel Worksheet Functions 4 September 7th 06 06:49 PM
return range of data from lookup function Boom1 Excel Worksheet Functions 0 August 18th 06 05:13 PM
custom function - return range GinaW Excel Programming 0 June 20th 06 12:13 AM
return used letters in a range function - an example [email protected] Excel Programming 0 December 10th 04 08:38 PM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"