PDA

View Full Version : Setting up an array



YellowLabPro
08-03-2007, 12:44 PM
I have two sheets, I set up a range for both and then loop through both adding a space to the end of the value.

Could I do an array for both the sheets and the loops?
I will need some syntax help here-
but my thoughts are something to this nature:
arrws("TGFF","TGVB", rngff, rngvb)

Hope this makes sense...

thanks for any info to get started- this is not a pressing matter... used for learning, my code works fine and is virtually instantaneous.... so no rush

thanks,

Doug

mikerickson
08-03-2007, 09:03 PM
I'm not real clear on what you are doing. Are you looping through a range and adding " " to each cell in that range? (Two ranges actualy.)

I'll give you a vauge responce and see if we can zero in on the issue.

Working with arrays is faster than read/writing to cells.

Dim myRange As Range, oneCell As Range

For Each oneCell In myRange
oneCell.Value = oneCell.Value & " "
Next cellis much slower than


Dim myArray As Variant, i As Long

myArray = myRange.Value
For i = LBound(myArray) To UBound(myArray)
myArray(i) = myArray(i) & " "
Next i
myRange.Value = myArray


If you aren't familiar with assigning a range's values to an array, this link (http://www.ozgrid.com/forum/showthread.php?t=68266) might help

moa
08-04-2007, 05:05 AM
You could use a two dimensional array so you have a column for the sheet names and one for the ranges so it's kind of ordered.

YellowLabPro
08-04-2007, 05:13 AM
Thanks Mike and Glen,
Mike I started reading your post on Ozgrid this morning, I will study this and post back- (won't be until late tonight... have to finish up a project today).

Glen- I am just delving into arrays- I have a concept, but not a lot of practical knowledge. Would need more info, possible example....., and explanation to better understand.

Thanks,

Doug