If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > returning a variant matrix Subscript out of range (Error 9)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-09, 11:24
mikezx10 mikezx10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 226
returning a variant matrix Subscript out of range (Error 9)

I am trying to return a matrix from a function and get the Subscript error on the last line of the code "GetData = vMatrix".

Im not sure what im doing wrong here is the code:

Private colEntries As New Collection
Sub start()

Dim s As String
Init ActiveSheet, s

End Sub
Public Sub Init(wks As Worksheet, ByRef err As String)

Dim je As JournalEntries
Set je = New JournalEntries

Dim var As Variant
var = GetData(ActiveSheet)

Set colEntries = je.GetEntries(var)

End Sub
Public Function GetData() As Variant

Dim vMatrix As Variant
Dim rngLastRow As Range

'a handle on the range we are working with
With ActiveSheet.Range("A:C")

'get the LastRow
Set rngLastRow = .Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious)

'if the range contains data then populate our variant array
If Not rngLastRow Is Nothing Then
vMatrix = .Resize(rngLastRow.Row - .Row + 1, .Columns.Count)
End If

End With
GetData = vMatrix
End Function
Reply With Quote
  #2 (permalink)  
Old 05-21-09, 06:20
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
Hi Mike,

You are passing a reference to the activesheet into your GetData() function, but the function doesn't have a parameter list?


Also, I mentioned on the other thread that auto-instantiation is not a good thing in VBA:
Code:
Private colEntries As New Collection
Hope that helps...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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