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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting an Excel range equal to an array 1

Status
Not open for further replies.

westma

Technical User
Jul 16, 2003
74
US
Hello

I currently have an one-dimensional array (distinctCusts) filled with strings. I am printing the values of the array onto a worksheet by looping through a "for" loop as follows:

Code:
With Range("X6")
  For iCust = 1 To nDistinctCusts
    .Offset(iCust, 0) = distinctCusts(iCust)
  Next
End With

My problem is that the array is quite large, so looping takes an undesirable amount of time. I would like to do this without looping by setting the range equal to the array - something like:

Code:
With Range("X6")
  Range(.Offset(1,0), .Offset(nDistinctCusts,0)).Value = distinctCusts
End With

I have had no success with this. Is there another way?

Thanks for your help!

 
I think you must use a two dimensional array.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Could you elaborate on this a bit more? I don't understand how that is supposed to work. Thanks again!
 
A starting point:
Dim distinctCusts()
' code that calculates nDistinctCusts
ReDim distinctCusts(nDistinctCusts, 1)
' code that populates distinctCusts(?, 1)
With Range("X6")
Range(.Offset(1, 0), .Offset(nDistinctCusts, 0)).Value = distinctCusts
End With

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry for the delayed response!

Tony:
Not getting an error - with the 1-d array, the range=array code displays only the first value in the array in all cells.

I did get the 2-d array to work as hoped, so thank you PHV, and (the rest) for you thoughts on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top