Okay Now I have got another problem with variants while working on it. I have succefully copied one variant to other. Now how do I determine the size of the new variant
Var1 = Sheet7.Range("B2:E2721").Value ' 1st variant
ReDim Var2(1 To UBound(Var, 1), 1 To UBound(Var, 2)) ' New variant
Ok after doing some calculations out of 2720 rows, I have copied 2020 rows into new variant and the other values from 2020 to 2720 are empty in the new variant . Now I have to know the size of new variant. I have tried these
ubound(var2,1) ' its giving the size as 2721 not as 2020
How can we find out the size of variant to the used range ignoring the empty one. because the size plays crucial part when we perform operations during loop or creating a another variant based on the other variant. and cant we define a variant without mentioning its dimensions? I Need to do split operation and add them to a variant, If that is the case I dont know how many split operations are performed and how many variables are taken out sometimes 20 or 40 , this should be copied to variant so we need a variant which is dynamic or something that can be resized
As per jonsca’s comment if you know how many records have been written or manipulated (2020) then you can cut the array from the 2721 record size at the end
The trick here is that you can’t redim the first dimension of an array and preserve the existing data so we need a three stage workaround
Sample below (dumps to B2:E2021 on your second sheet)