Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
shitij
 
Posts: n/a
Default Filling excel entire row/column instead of single cell from an array


Hi,
I have a 2-dimensional variant array. If I want to fill up the excel
worksheet, the way to fill it up using VB program is:-
If rCount < 0 Then
For iRow = 1 To rCount
For iColumn = 1 To cCount
ws.cells(iRow, iColumn).Value = arr(iRow, iColumn)
Next
Next
End If

Here, ws = Excel worksheet object
arr() = two-dimensional array of type variant from where
values need to be filled
rCount = Number of Rows
cCount = Number of Columns
iRow = counter for rows and iColumn = counter for columns

My problem is that loop within a loop does take lot of time, if rows
and columns are around 50 or so. Is there anyway to avoid loop so as to
decrease loop within loop time.

Thanks in advance


--
****ij
------------------------------------------------------------------------
****ij's Profile: http://www.excelforum.com/member.php...o&userid=25145
View this thread: http://www.excelforum.com/showthread...hreadid=386391

  #2   Report Post  
KL
 
Posts: n/a
Default

Hi,

This one works for me:

Sub test()
Dim arr(1 To 20, 1 To 10)
For j = 1 To 10
For i = 1 To 20
arr(i, j) = i + j
Next i
Next j
Range("a1").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub

Regards,
KL



"****ij" wrote in
message ...

Hi,
I have a 2-dimensional variant array. If I want to fill up the excel
worksheet, the way to fill it up using VB program is:-
If rCount < 0 Then
For iRow = 1 To rCount
For iColumn = 1 To cCount
ws.cells(iRow, iColumn).Value = arr(iRow, iColumn)
Next
Next
End If

Here, ws = Excel worksheet object
arr() = two-dimensional array of type variant from where
values need to be filled
rCount = Number of Rows
cCount = Number of Columns
iRow = counter for rows and iColumn = counter for columns

My problem is that loop within a loop does take lot of time, if rows
and columns are around 50 or so. Is there anyway to avoid loop so as to
decrease loop within loop time.

Thanks in advance


--
****ij
------------------------------------------------------------------------
****ij's Profile:
http://www.excelforum.com/member.php...o&userid=25145
View this thread: http://www.excelforum.com/showthread...hreadid=386391



  #3   Report Post  
shitij
 
Posts: n/a
Default


Thanks for the appropriate reply. That does really helped me. In
continuation to above reply, can you advise me the way to have cells of
whole excel file in an array in a single shot instead of reading it in a
loof of reading cells individually. Your words of little help can work
wonders for me.
Once again, thanks for the suitable reply.


--
****ij
------------------------------------------------------------------------
****ij's Profile: http://www.excelforum.com/member.php...o&userid=25145
View this thread: http://www.excelforum.com/showthread...hreadid=386391

  #4   Report Post  
KL
 
Posts: n/a
Default

Hi ****ij,

Do you really mean "cells of whole excel file" or maybe the cells of the
whole used range on a sheet of that file? If it is the latter then it is as
easy as the following:

Dim Arr as Variant
arr=ActiveSheet.UsedRange.Value

Regards,
KL

"****ij" wrote in
message ...

Thanks for the appropriate reply. That does really helped me. In
continuation to above reply, can you advise me the way to have cells of
whole excel file in an array in a single shot instead of reading it in a
loof of reading cells individually. Your words of little help can work
wonders for me.
Once again, thanks for the suitable reply.


--
****ij
------------------------------------------------------------------------
****ij's Profile:
http://www.excelforum.com/member.php...o&userid=25145
View this thread: http://www.excelforum.com/showthread...hreadid=386391



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
Filling cells (autofil?) in Excel 2003 Hnelg Excel Discussion (Misc queries) 3 July 5th 05 02:47 PM
How can I convert entire columns of text to Uppercase in Excel? dplantlady Excel Worksheet Functions 8 May 1st 05 06:51 PM
Excel 2003 Referencing multiple workbooks via single variable BBohannon Excel Worksheet Functions 0 April 20th 05 08:32 PM
how to do global replace in hyperlinks for entire excel document? AKennedy Excel Discussion (Misc queries) 2 March 19th 05 04:27 PM
how can I split a single cell diagonally in Excel 2000 Forrest Excel Discussion (Misc queries) 2 January 27th 05 11:47 PM


All times are GMT +1. The time now is 12:28 AM.

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"