Writing array to a range
wrote in message
...
I have one other question related to this. If I only wanted to retain the
rows in which there was a certain value within it how would that be done?
Make a sub array (from the main array) of the rows that contain this value
and then send this to a range on a worksheet.
Something like-
If Len(Trim(LineArray(x))) = 0 Then
' do nothing
Elseif Instr(1, LineArray(x), "abc") Then ' keep rows that contain abc
rw = rw + 1
add to the main array after redim preserve if/as necessary, not in row-x
(the loop counter) as I gave last time but in row-rw
After the loop the main array might have empty rows, so resize the range to
size of the array that's been populated
Destination.Resize(rw, maxCol + 1).value = DataArray
Note LBound in both dimensions of the main array is probably zero, 'rw' is
presumably the actual count but maxCol is probably the count including zero,
hence maxCol + 1. As written above is a bit lazy, best check exactly what
you've got, not least you've acutally got anything else it'll error.
Regards,
Peter T
|