Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Reading to a 1-D array...Error

Hi,

I am trying to read a single column into an array. The code that I
have written is giving me a Runtime Error '1004'- Application -
defined or Object - defined error. Could you please help me to
understand the mistake...The code is as below.

Function GenMArray() As Variant

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Activate
ActiveCell.Offset(3, 1).Select

MsgBox "The address is " & ActiveCell.Address
GenMArray = Application.Transpose(Range(ActiveCell,
ActiveCell.End(xlDown)))

End Function

Thanks,
shi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Reading to a 1-D array...Error

Shi,

This worked for me:

Sub TryNow()
Dim myArray As Variant
Dim i As Integer

myArray = GenMArray
For i = LBound(myArray) To UBound(myArray)
MsgBox myArray(i)
Next i
End Sub

Function GenMArray() As Variant

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Activate
ActiveCell.Offset(3, 1).Select

MsgBox "The address is " & ActiveCell.Address
GenMArray = Application.Transpose(Range(ActiveCell, ActiveCell.End(xlDown)))

End Function

HTH,
Bernie
MS Excel MVP


"shishi" wrote in message
oups.com...
Hi,

I am trying to read a single column into an array. The code that I
have written is giving me a Runtime Error '1004'- Application -
defined or Object - defined error. Could you please help me to
understand the mistake...The code is as below.

Function GenMArray() As Variant

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Activate
ActiveCell.Offset(3, 1).Select

MsgBox "The address is " & ActiveCell.Address
GenMArray = Application.Transpose(Range(ActiveCell,
ActiveCell.End(xlDown)))

End Function

Thanks,
shi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Reading to a 1-D array...Error

Hi,

I have made my code exactly the same as the way Bernie has suggested,

but still it fails. I ran Debug-Step Into. When it executes the line
GenMArray = Application.Transpose(Range(Ac*tiveCell,
ActiveCell.End(xlDown))) ,
it come up with the Runtime Error '1004'- Application -
defined or Object - defined error. But if I place the mouse pointer
on top of the Range(Ac*tiveCell, ActiveCell.End(xlDown)), part of the
stement,
I can see that it has read the actual values. Any clues...I am running
out
solutions to fix this problem..Thanks for all your advice.

shi

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Reading to a 1-D array...Error

What does the second msgbox say:

Function GenMArray() As Variant

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Activate
ActiveCell.Offset(3, 1).Select

MsgBox "The address is " & ActiveCell.Address
MsgBox "The array is " & Range(ActiveCell, ActiveCell.End(xlDown)).Address
GenMArray = Application.Transpose(Range(ActiveCell, ActiveCell.End(xlDown)))

End Function


HTH,
Bernie
MS Excel MVP


"shishi" wrote in message
oups.com...
Hi,

I have made my code exactly the same as the way Bernie has suggested,

but still it fails. I ran Debug-Step Into. When it executes the line
GenMArray = Application.Transpose(Range(Ac*tiveCell,
ActiveCell.End(xlDown))) ,
it come up with the Runtime Error '1004'- Application -
defined or Object - defined error. But if I place the mouse pointer
on top of the Range(Ac*tiveCell, ActiveCell.End(xlDown)), part of the
stement,
I can see that it has read the actual values. Any clues...I am running
out
solutions to fix this problem..Thanks for all your advice.

shi


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Reading to a 1-D array...Error

I don't know what I was thinking: a function can't change the selection or the active sheet. Try
your function this way:

Function GenMArray() As Variant
Dim myCell As Range
Set myCell = ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Offset(3, 1)

MsgBox "The address is " & myCell.Address
MsgBox "The array is " & Range(myCell, myCell.End(xlDown)).Address
GenMArray = Application.Transpose(Range(myCell, myCell.End(xlDown)))

End Function

HTH,
Bernie
MS Excel MVP


"shishi" wrote in message
oups.com...
Hi,

I have made my code exactly the same as the way Bernie has suggested,

but still it fails. I ran Debug-Step Into. When it executes the line
GenMArray = Application.Transpose(Range(Ac*tiveCell,
ActiveCell.End(xlDown))) ,
it come up with the Runtime Error '1004'- Application -
defined or Object - defined error. But if I place the mouse pointer
on top of the Range(Ac*tiveCell, ActiveCell.End(xlDown)), part of the
stement,
I can see that it has read the actual values. Any clues...I am running
out
solutions to fix this problem..Thanks for all your advice.

shi




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Reading to a 1-D array...Error

Bernie - can you clarify your statement?
There is no such limitation on a function if it is used as you illustrated
it - called by a vba procedure. If it is used as a UDF - used in a
worksheet cell, then it has that limitation.

Just some added considerations (though not the error cited):
Problems also may be because the number of cells in the range being
transposed is greater than 5461 (depends on the version of excel).

http://support.microsoft.com/?id=177991
XL: Limitations of Passing Arrays to Excel Using Automation (Q177991)
--
Regards,
Tom Ogilvy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
I don't know what I was thinking: a function can't change the selection or

the active sheet. Try
your function this way:

Function GenMArray() As Variant
Dim myCell As Range
Set myCell =

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Offset(3, 1)

MsgBox "The address is " & myCell.Address
MsgBox "The array is " & Range(myCell, myCell.End(xlDown)).Address
GenMArray = Application.Transpose(Range(myCell, myCell.End(xlDown)))

End Function

HTH,
Bernie
MS Excel MVP


"shishi" wrote in message
oups.com...
Hi,

I have made my code exactly the same as the way Bernie has suggested,

but still it fails. I ran Debug-Step Into. When it executes the line
GenMArray = Application.Transpose(Range(Ac*tiveCell,
ActiveCell.End(xlDown))) ,
it come up with the Runtime Error '1004'- Application -
defined or Object - defined error. But if I place the mouse pointer
on top of the Range(Ac*tiveCell, ActiveCell.End(xlDown)), part of the
stement,
I can see that it has read the actual values. Any clues...I am running
out
solutions to fix this problem..Thanks for all your advice.

shi




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Reading to a 1-D array...Error

Tom,

The original post didn't show how it was being called - I called it from a sub to test it, but then
later realized that the OP might be calling it from a worksheet. The only runtime error 1004 I was
able to generate was when I called the function with another worksheet active, but it was the
"Activate method of range class failed"....

The second msgbox was meant to show the address of the cells he was trying to transpose: I didn't
get the same error message as he was describing when I used a very large range.

Bernie
MS Excel MVP


"Tom Ogilvy" wrote in message ...
Bernie - can you clarify your statement?
There is no such limitation on a function if it is used as you illustrated
it - called by a vba procedure. If it is used as a UDF - used in a
worksheet cell, then it has that limitation.

Just some added considerations (though not the error cited):
Problems also may be because the number of cells in the range being
transposed is greater than 5461 (depends on the version of excel).

http://support.microsoft.com/?id=177991
XL: Limitations of Passing Arrays to Excel Using Automation (Q177991)
--
Regards,
Tom Ogilvy



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
I don't know what I was thinking: a function can't change the selection or

the active sheet. Try
your function this way:

Function GenMArray() As Variant
Dim myCell As Range
Set myCell =

ThisWorkbook.Sheets("SUMMARY").Range("NO_OF_MODULE S").Offset(3, 1)

MsgBox "The address is " & myCell.Address
MsgBox "The array is " & Range(myCell, myCell.End(xlDown)).Address
GenMArray = Application.Transpose(Range(myCell, myCell.End(xlDown)))

End Function

HTH,
Bernie
MS Excel MVP


"shishi" wrote in message
oups.com...
Hi,

I have made my code exactly the same as the way Bernie has suggested,

but still it fails. I ran Debug-Step Into. When it executes the line
GenMArray = Application.Transpose(Range(Ac*tiveCell,
ActiveCell.End(xlDown))) ,
it come up with the Runtime Error '1004'- Application -
defined or Object - defined error. But if I place the mouse pointer
on top of the Range(Ac*tiveCell, ActiveCell.End(xlDown)), part of the
stement,
I can see that it has read the actual values. Any clues...I am running
out
solutions to fix this problem..Thanks for all your advice.

shi






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
Reading a Range to an Array Kevin H. Stecyk[_2_] Excel Programming 6 January 26th 05 11:01 PM
Reading a VBA Array - Thanks SMS - John Howard Excel Programming 0 October 30th 04 11:35 PM
Reading .csv file into array mousetrap Excel Programming 1 November 26th 03 07:47 AM
reading an arbitrary selection into a 1D array Jamie Martin[_2_] Excel Programming 5 September 30th 03 05:25 PM
Reading a cell into an array Tick-Tock Excel Programming 2 September 11th 03 07:33 PM


All times are GMT +1. The time now is 10:36 PM.

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

About Us

"It's about Microsoft Excel"