Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Empty Error? 1

Status
Not open for further replies.

mbarnett

MIS
Jun 15, 2003
123
US
Quick question - I have a two part macro,the first part that reads the data is working. It crashes on this part- and I get Subscript out of range. i did a debug the reason, there is not data that match my criteria in the first part (Empty). How can I perform incorporate a test to exit routine -

Sub print_ou2117(info() As CanUseForAll)
Dim i As Integer
Dim q As Long

Windows("FO.xls").Activate
Sheets("Sheet3").Select

Application.Calculation = xlCalculationManual

q = LastUsedRow(Range("A:E"))
For i = 1 To UBound(info)
Cells(i + q, 1).Value = info(i).edate
Cells(i + q, 2).Value = info(i).trade_id
Cells(i + q, 3).Value = info(i).cflow
Cells(i + q, 4).Value = info(i).source
Cells(i + q, 5).Value = info(i).ou
Next i

Application.Calculation = xlCalculationAutomatic
Application.Calculate

End Sub
 
Hi mbarnett,

If I understand correctly the info() array may be empty. If so, change your loop to ..

Code:
For i = LBound(info) To UBound(info)

Depending on your precise circumstances you may need to play around a little, but it should see you through. The loop will be executed zero times for an array of zero elements which is what I think you want.

Enjoy,
Tony
 
Hi Tony,

Thanks for the quick response, It still crashes on For i = LBound(info) To UBound(info). In the watch section on one of my expressions Type=Empty and value =<Out of context>

Thanks Mark
 
Hi Mark,

If I read you right, Info is a dynamic array that may never have been ReDimmed. If so, I don't know any check to pick it up but you could do something like ...

Code:
On Error Resume Next
If UBound(info) = 0 Then
    Exit Sub
End If
On Error GoTo 0

All this does is force the code to check if it gets an error referencing the array and, if so quits. Not very good but th best I can come up with at the moment.

Enjoy,
Tony
 
Hi Tony,

I appreciate the help. I will give it a try.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top