开发者

Copy a complete row of one var to other var

开发者 https://www.devze.com 2023-04-10 05:21 出处:网络
I have a variant like these ranging from var(1,42) to var(4000,42) I have done some operations based on the requirement and filled the 42nd column of var with 0\'s and 1\'s. Now I have to import

I have a variant like these

 ranging from var(1,42) to var(4000,42)

I have done some operations based on the requirement and filled the 42nd column of var with 0's and 1's. Now I have to import only those rows of var to the sheet that has 1 in its 42 nd column. These is what i have coded

t=1
For i = 1 to 4000
      If var(i,42) = 1  Then
         For k = 1 to 41
           var2(t,k) = var(i,k)
         Next k
         t = t + 1
      End If
Next i

What I think is to copy the needed rows from one var to other new_var,Im using looping something like these

for k = 1 to 41 ' the inner loop

But people here says looping is time consuming. They even say its a bad style of writing code but I did not find a better way to copy one var to other var, I mean only the needed rows.Say suppose I have to copy the 30th row contents of one var to other var, Then Im using looping to copy from 1 to 4开发者_开发技巧1 the column contents, but is there something like copying the entire row of var to the other var?


Niko,

It is slow to loop ranges - looping variant arrays is exteremely fast. And it is certainly not bad code!

Your approach is fine.

So the same approach as my solution in Is it possible to dump a certain range of variant into the sheet? is fine for you to use. It writes 50,000 cells or so in to a second array, then dumps it to a sheet in less than a second


You ask:

is there something like copying the entire row of var to the other var? [presumably in a single command]

The answer is: no, there isn't. Your approach is the only one I know of.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号